cowork-flow 2.4.1 → 2.5.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/README.en.md +2 -1
  3. package/README.md +2 -1
  4. package/docs/architecture.en.md +2 -0
  5. package/docs/architecture.md +2 -0
  6. package/docs/hosts.en.md +15 -0
  7. package/docs/hosts.md +15 -0
  8. package/package.json +2 -2
  9. package/presets/claude-code/.claude-plugin/plugin.json +1 -1
  10. package/presets/codex/.codex-plugin/plugin.json +1 -1
  11. package/presets/kimi-code/.kimi-plugin/plugin.json +1 -1
  12. package/presets/qoder/.qoder-plugin/plugin.json +1 -1
  13. package/presets/zcode/.zcode-plugin/plugin.json +1 -1
  14. package/src/commands/host-inspect.js +86 -0
  15. package/src/commands/host.js +42 -18
  16. package/src/commands/init.js +100 -3
  17. package/src/commands/install-claude-code-plugin.js +53 -2
  18. package/src/commands/install-codex-plugin.js +114 -4
  19. package/src/commands/install-dsh-hook.js +51 -0
  20. package/src/commands/install-dsh-preset.js +46 -4
  21. package/src/commands/install-kimi-code-plugin.js +61 -2
  22. package/src/commands/install-kimi-hook.js +84 -2
  23. package/src/commands/install-opencode-plugin.js +58 -2
  24. package/src/commands/install-qoder-plugin.js +67 -3
  25. package/src/commands/install-zcode-plugin.js +77 -2
  26. package/src/commands/registry.js +20 -5
  27. package/src/lib/dsh-home.js +2 -2
  28. package/template/.cowork-flow/.version +1 -1
  29. package/template/.cowork-flow/scripts/adapters/cli/plan.py +218 -0
  30. package/template/.cowork-flow/scripts/adapters/host/host_manifest.py +4 -0
  31. package/template/.cowork-flow/scripts/adapters/host/workflow_state_hook.py +1 -3
  32. package/template/.cowork-flow/scripts/infra/files.py +0 -13
  33. package/template/.cowork-flow/scripts/run.py +3 -1
  34. package/template/.cowork-flow/scripts/services/ac_evidence.py +1 -1
  35. package/template/.cowork-flow/scripts/services/decision_anchor_schema.py +65 -0
  36. package/template/.cowork-flow/scripts/services/fact_view.py +2 -75
  37. package/template/.cowork-flow/scripts/services/lifecycle_checks.py +1 -1
  38. package/template/.cowork-flow/scripts/services/plan_readiness.py +655 -0
  39. package/template/.cowork-flow/scripts/services/plan_scaffold.py +133 -0
  40. package/template/.cowork-flow/scripts/services/plan_schema.py +40 -0
  41. package/template/.cowork-flow/scripts/services/task_context.py +12 -0
  42. package/template/.cowork-flow/scripts/services/task_creation.py +23 -24
  43. package/template/.cowork-flow/spec/contracts/host-install-inspection.md +174 -0
  44. package/template/.cowork-flow/spec/contracts/index.md +1 -0
  45. package/template/.cowork-flow/spec/contracts/plan-binding.md +62 -4
  46. package/template/.cowork-flow/spec/runtime/contract-registry.json +17 -1
  47. package/template/skills/runtime-health/scripts/doctor.py +538 -489
  48. package/template/skills/task-planning/SKILL.md +24 -0
  49. package/template/skills/task-review/scripts/review_check.py +33 -6
@@ -7,6 +7,8 @@ import argparse
7
7
  import json
8
8
  import os
9
9
  import re
10
+ import shutil
11
+ import subprocess
10
12
  import sys
11
13
  from datetime import datetime, timezone
12
14
  from pathlib import Path
@@ -855,75 +857,64 @@ def check_mcp_registration(repo_root: Path) -> list[dict[str, str]]:
855
857
  return issues
856
858
 
857
859
 
858
- def _dsh_preset_dir() -> Path:
859
- base = os.environ.get("DSH_HOME") or str(Path.home() / ".dsh")
860
- return Path(base) / ".agent-presets" / "cowork-flow"
861
-
862
-
863
860
  def check_dsh_preset(repo_root: Path) -> list[dict[str, str]]:
864
- """DSH preset freshness. Advisory only, and silent when the preset is
865
- absent: it is a machine-level asset installed once, so it does not
866
- update with npm or sync. Report an unknown or stale installed version
861
+ """DSH preset freshness from the CLI-owned install-state read model.
862
+
863
+ Advisory only, and silent while the project never selected DSH or when the
864
+ preset is absent: it is a machine-level asset installed once, so it does
865
+ not update with npm or sync. Report an unknown or stale installed version
867
866
  instead of assuming the injection logic matches this project."""
868
- preset_dir = _dsh_preset_dir()
869
- if not preset_dir.is_dir():
867
+ adapter = repo_root / DIR_WORKFLOW / "adapters" / "dsh" / "adapter.yaml"
868
+ if not adapter.is_file():
870
869
  return []
871
- marker = preset_dir / ".cowork-flow-preset.json"
872
- if not marker.is_file():
873
- return [
874
- _issue(
875
- code="PRESET-UNKNOWN-VERSION",
876
- severity="warning",
877
- path=str(marker),
878
- message=(
879
- "DSH preset is installed without a version marker; its "
880
- "injection logic may predate the current release"
881
- ),
882
- command_hint="cwf host add dsh --component preset --force",
883
- contract="runtime-health:dsh-preset",
884
- )
885
- ]
886
- recorded: object = None
887
- try:
888
- recorded = json.loads(marker.read_text(encoding="utf-8")).get("version")
889
- except (OSError, json.JSONDecodeError, ValueError, AttributeError):
890
- recorded = None
891
- if not isinstance(recorded, str) or not recorded:
870
+ row, unavailable = _inspect_component_row(
871
+ repo_root, "dsh", "preset", "the dsh preset"
872
+ )
873
+ if unavailable is not None:
874
+ return unavailable
875
+ status = row.get("status")
876
+ path = _inspect_path(row, "dsh")
877
+ reason = str(row.get("reason") or "")
878
+
879
+ if status == "missing":
880
+ return []
881
+ if status == "broken":
892
882
  return [
893
883
  _issue(
894
884
  code="PRESET-UNKNOWN-VERSION",
895
885
  severity="warning",
896
- path=str(marker),
886
+ path=str(path),
897
887
  message=(
898
- "DSH preset version marker is unreadable; its injection "
899
- "logic may predate the current release"
888
+ f"DSH preset is installed without a readable version marker "
889
+ f"({reason}); its injection logic may predate the current "
890
+ "release"
900
891
  ),
901
892
  command_hint="cwf host add dsh --component preset --force",
902
893
  contract="runtime-health:dsh-preset",
903
894
  )
904
895
  ]
905
- try:
906
- project_version = (
907
- repo_root / DIR_WORKFLOW / ".version"
908
- ).read_text(encoding="utf-8").strip()
909
- except OSError:
910
- return []
911
- if not project_version or recorded == project_version:
896
+ if status in ("installed", "stale"):
897
+ project_version = _project_stale_version(row, repo_root)
898
+ if project_version is not None:
899
+ recorded = row.get("version") or "an unknown version"
900
+ return [
901
+ _issue(
902
+ code="PRESET-STALE",
903
+ severity="warning",
904
+ path=str(path),
905
+ message=_project_stale_message(
906
+ "DSH preset",
907
+ recorded,
908
+ project_version,
909
+ "the preset does not update with sync or npm, so "
910
+ "injection may lag the project runtime",
911
+ ),
912
+ command_hint="cwf host add dsh --component preset --force",
913
+ contract="runtime-health:dsh-preset",
914
+ )
915
+ ]
912
916
  return []
913
- return [
914
- _issue(
915
- code="PRESET-STALE",
916
- severity="warning",
917
- path=str(marker),
918
- message=(
919
- f"DSH preset was installed from {recorded} but this project "
920
- f"runs {project_version}; the preset does not update with "
921
- "sync or npm, so injection may lag the project runtime"
922
- ),
923
- command_hint="cwf host add dsh --component preset --force",
924
- contract="runtime-health:dsh-preset",
925
- )
926
- ]
917
+ return _unexpected_inspect_status("dsh", status)
927
918
 
928
919
 
929
920
  def _project_version(repo_root: Path) -> str:
@@ -935,13 +926,19 @@ def _project_version(repo_root: Path) -> str:
935
926
  return ""
936
927
 
937
928
 
938
- _HOOK_START_MARK = "# cowork-flow: kimi hook start."
939
- _KIMI_HOOK_MARKER = ".cowork-flow-kimi-hook.json"
940
- _KIMI_HOOK_CONTRACT = "runtime-health:kimi-hook"
929
+ def _project_stale_version(row: dict[str, object], repo_root: Path) -> str | None:
930
+ """The project runtime version when the installed payload does not match it.
941
931
 
932
+ Inspect's own `stale` compares the payload with the running CLI. Doctor
933
+ answers for this project, so it compares with the project's `.version`
934
+ instead; a payload with no recorded version is unknown, not fresh."""
935
+ project_version = _project_version(repo_root)
936
+ if project_version and row.get("version") != project_version:
937
+ return project_version
938
+ return None
942
939
 
943
- def _kimi_home() -> Path:
944
- return Path(os.environ.get("KIMI_CODE_HOME") or (Path.home() / ".kimi-code"))
940
+
941
+ _KIMI_HOOK_CONTRACT = "runtime-health:kimi-hook"
945
942
 
946
943
 
947
944
  def _kimi_hook_warning(
@@ -959,72 +956,71 @@ def _kimi_hook_warning(
959
956
  ]
960
957
 
961
958
 
962
- def _marker_version(marker: Path) -> str | None:
963
- try:
964
- recorded = json.loads(marker.read_text(encoding="utf-8")).get("version")
965
- except (OSError, json.JSONDecodeError, ValueError, AttributeError):
966
- return None
967
- return recorded if isinstance(recorded, str) and recorded else None
968
-
969
-
970
959
  def check_kimi_hook(repo_root: Path) -> list[dict[str, str]]:
971
- """Kimi Code hook health. Advisory only, and silent while Kimi Code is
972
- not configured at all: the hook is a machine-level asset installed once
973
- into the user-level config.toml, so it does not update with npm or sync.
974
- Report an unknown or stale installed version instead of assuming the
975
- injection logic matches this project."""
976
- home = _kimi_home()
977
- config = home / "config.toml"
978
- try:
979
- config_text = config.read_text(encoding="utf-8")
980
- except OSError:
960
+ """Kimi Code hook health from the CLI-owned install-state read model.
961
+
962
+ Silent while unselected or unconfigured; report unknown or stale versions
963
+ instead of assuming the machine-level hook matches this project."""
964
+ adapter = repo_root / DIR_WORKFLOW / "adapters" / "kimi-code" / "adapter.yaml"
965
+ if not adapter.is_file():
981
966
  return []
982
- if _HOOK_START_MARK not in config_text:
967
+ row, unavailable = _inspect_component_row(
968
+ repo_root, "kimi-code", "hook", "the kimi-code hook"
969
+ )
970
+ if unavailable is not None:
971
+ return unavailable
972
+ status = row.get("status")
973
+ path = _inspect_path(row, "kimi-code")
974
+ reason = str(row.get("reason") or "")
975
+
976
+ if status == "missing":
977
+ if reason == "config file is absent":
978
+ return []
983
979
  return _kimi_hook_warning(
984
980
  "HOOK-NOT-INSTALLED",
985
- config,
981
+ path,
986
982
  "Kimi Code is configured but no cowork-flow hook is registered; "
987
983
  "sessions inject no workflow context",
988
984
  "cwf host add kimi-code --component hook",
989
985
  )
990
- shim = home / "hooks" / "cowork-flow-inject.mjs"
991
- if not shim.is_file():
992
- return _kimi_hook_warning(
993
- "HOOK-SHIM-MISSING",
994
- shim,
995
- "config.toml registers the cowork-flow hook but its shim is "
996
- "missing; the host runs a command that cannot start",
997
- "cwf host add kimi-code --component hook",
998
- )
999
- marker = home / "hooks" / _KIMI_HOOK_MARKER
1000
- if not marker.is_file():
1001
- return _kimi_hook_warning(
1002
- "HOOK-UNKNOWN-VERSION",
1003
- marker,
1004
- "Kimi Code hook is installed without a version marker; its "
1005
- "injection logic may predate the current release",
1006
- "cwf host add kimi-code --component hook",
1007
- )
1008
- recorded = _marker_version(marker)
1009
- if recorded is None:
1010
- return _kimi_hook_warning(
1011
- "HOOK-UNKNOWN-VERSION",
1012
- marker,
1013
- "Kimi Code hook version marker is unreadable; its injection logic "
1014
- "may predate the current release",
1015
- "cwf host add kimi-code --component hook",
986
+ if status == "broken":
987
+ if reason == "shim is missing":
988
+ return _kimi_hook_warning(
989
+ "HOOK-SHIM-MISSING",
990
+ path,
991
+ "config.toml registers the cowork-flow hook but its shim is "
992
+ "missing; the host runs a command that cannot start",
993
+ "cwf host add kimi-code --component hook",
994
+ )
995
+ if reason.startswith("version marker"):
996
+ return _kimi_hook_warning(
997
+ "HOOK-UNKNOWN-VERSION",
998
+ path,
999
+ f"Kimi Code hook {reason}; its injection logic may predate the "
1000
+ "current release",
1001
+ "cwf host add kimi-code --component hook",
1002
+ )
1003
+ return _host_inspect_unavailable_issue(
1004
+ "kimi-code", {"reason": f"host inspect reported {reason!r}"}
1016
1005
  )
1017
- project_version = _project_version(repo_root)
1018
- if not project_version or recorded == project_version:
1006
+ if status in ("installed", "stale"):
1007
+ project_version = _project_stale_version(row, repo_root)
1008
+ if project_version is not None:
1009
+ recorded = row.get("version") or "an unknown version"
1010
+ return _kimi_hook_warning(
1011
+ "HOOK-STALE",
1012
+ path,
1013
+ _project_stale_message(
1014
+ "Kimi Code hook",
1015
+ recorded,
1016
+ project_version,
1017
+ "the hook does not update with sync or npm, so injection "
1018
+ "may lag the project runtime",
1019
+ ),
1020
+ "cwf host add kimi-code --component hook",
1021
+ )
1019
1022
  return []
1020
- return _kimi_hook_warning(
1021
- "HOOK-STALE",
1022
- marker,
1023
- f"Kimi Code hook was installed from {recorded} but this project runs "
1024
- f"{project_version}; the hook does not update with sync or npm, so "
1025
- "injection may lag the project runtime",
1026
- "cwf host add kimi-code --component hook",
1027
- )
1023
+ return _unexpected_inspect_status("kimi-code", status)
1028
1024
 
1029
1025
 
1030
1026
  _QODER_PLUGIN_CONTRACT = "runtime-health:qoder-plugin"
@@ -1044,195 +1040,319 @@ def _qoder_warning(code: str, path: Path, message: str, hint: str) -> list[dict[
1044
1040
  ]
1045
1041
 
1046
1042
 
1047
- def _qoder_home() -> Path:
1048
- configured = (os.environ.get("QODER_CONFIG_DIR") or "").strip()
1049
- return Path(configured) if configured else Path.home() / ".qoder"
1043
+ _ZCODE_PLUGIN_CONTRACT = "runtime-health:zcode-plugin"
1044
+
1045
+
1046
+ def _zcode_warning(code: str, path: Path, message: str, hint: str) -> list[dict[str, str]]:
1047
+ return [
1048
+ _issue(
1049
+ code=code,
1050
+ severity="warning",
1051
+ path=str(path),
1052
+ message=message,
1053
+ command_hint=hint,
1054
+ contract=_ZCODE_PLUGIN_CONTRACT,
1055
+ )
1056
+ ]
1057
+
1058
+
1059
+ _HOST_INSPECT_CONTRACT = "runtime-health:host-inspect"
1060
+ HOST_INSPECT_TIMEOUT_SECONDS = 5
1061
+ _HOST_INSPECT_CACHE: dict[str, dict[str, object]] = {}
1050
1062
 
1051
1063
 
1052
- def _qoder_registry_entry(registry_path: Path) -> dict[str, object] | None:
1053
- """The first registry entry cowork-flow owns, or None.
1064
+ def _host_inspect_command() -> list[str] | None:
1065
+ """The CLI invocation that owns machine install-state facts.
1054
1066
 
1055
- Qoder documents this file's shape nowhere, so an unreadable or unexpected
1056
- file is reported as "not installed" rather than trusted.
1067
+ A configured JavaScript entry runs through Node, so a checkout can be
1068
+ inspected without installing it globally.
1057
1069
  """
1058
- try:
1059
- registry = json.loads(registry_path.read_text(encoding="utf-8"))
1060
- except (OSError, json.JSONDecodeError, ValueError):
1061
- return None
1062
- plugins = registry.get("plugins") if isinstance(registry, dict) else None
1063
- entries = plugins.get(QODER_PLUGIN_KEY) if isinstance(plugins, dict) else None
1064
- if isinstance(entries, list) and entries and isinstance(entries[0], dict):
1065
- return entries[0]
1070
+ configured = (os.environ.get("COWORK_FLOW_CLI") or "").strip()
1071
+ if configured:
1072
+ if configured.lower().endswith((".js", ".mjs", ".cjs")):
1073
+ node = shutil.which("node")
1074
+ return [node, configured] if node else None
1075
+ return [configured]
1076
+ for name in ("cwf", "cowork-flow"):
1077
+ found = shutil.which(name)
1078
+ if found:
1079
+ return [found]
1066
1080
  return None
1067
1081
 
1068
1082
 
1069
- def _payload_manifest(platform_id: str, repo_root: Path) -> str | None:
1070
- """Plugin manifest path inside a host's payload, taken from the host asset
1071
- manifest declaration. Returns None when the declaration cannot be read, so a
1072
- caller falls back to its own literal instead of skipping the check."""
1083
+ def _host_inspect_unavailable(reason: str) -> dict[str, object]:
1084
+ return {"available": False, "reason": reason, "hosts": {}}
1085
+
1086
+
1087
+ def _run_host_inspect() -> dict[str, object]:
1088
+ command = _host_inspect_command()
1089
+ if command is None:
1090
+ return _host_inspect_unavailable(
1091
+ "the cowork-flow CLI is not on PATH; set COWORK_FLOW_CLI or install it"
1092
+ )
1073
1093
  try:
1074
- manifest = load_host_manifest(_distribution_root(repo_root))
1075
- platform = manifest.platform(platform_id)
1076
- except HostManifestError:
1077
- return None
1078
- return platform.payload.manifest if platform.payload else None
1094
+ completed = subprocess.run(
1095
+ [*command, "host", "inspect", "--json"],
1096
+ capture_output=True,
1097
+ text=True,
1098
+ encoding="utf-8",
1099
+ timeout=HOST_INSPECT_TIMEOUT_SECONDS,
1100
+ stdin=subprocess.DEVNULL,
1101
+ check=False,
1102
+ )
1103
+ except (OSError, subprocess.SubprocessError, UnicodeDecodeError) as error:
1104
+ return _host_inspect_unavailable(f"host inspect could not run: {error}")
1105
+ if completed.returncode != 0:
1106
+ return _host_inspect_unavailable(
1107
+ f"host inspect exited with {completed.returncode}"
1108
+ )
1109
+ try:
1110
+ payload = json.loads(completed.stdout)
1111
+ except (json.JSONDecodeError, ValueError):
1112
+ return _host_inspect_unavailable("host inspect returned invalid JSON")
1113
+ if not isinstance(payload, dict) or payload.get("schemaVersion") != 1:
1114
+ return _host_inspect_unavailable(
1115
+ "host inspect does not support schemaVersion 1; upgrade cowork-flow"
1116
+ )
1117
+ rows = payload.get("hosts")
1118
+ if not isinstance(rows, list):
1119
+ return _host_inspect_unavailable("host inspect returned no hosts list")
1120
+ hosts: dict[str, dict[str, object]] = {}
1121
+ components: dict[str, dict[str, object]] = {}
1122
+ for row in rows:
1123
+ if not isinstance(row, dict) or not isinstance(row.get("id"), str):
1124
+ continue
1125
+ host_id = row["id"]
1126
+ component = str(row.get("component") or "")
1127
+ components[f"{host_id}:{component}"] = row
1128
+ hosts.setdefault(host_id, row)
1129
+ return {
1130
+ "available": True,
1131
+ "reason": "",
1132
+ "hosts": hosts,
1133
+ "components": components,
1134
+ }
1135
+
1136
+
1137
+ def _inspect_row(
1138
+ facts: dict[str, object], host_id: str, component: str
1139
+ ) -> dict[str, object] | None:
1140
+ row = facts.get("components", {}).get(f"{host_id}:{component}")
1141
+ return row if isinstance(row, dict) else None
1142
+
1143
+
1144
+ def _host_inspect_facts(repo_root: Path) -> dict[str, object]:
1145
+ """One inspect call per doctor run; the facts are read-only."""
1146
+ key = str(repo_root)
1147
+ cached = _HOST_INSPECT_CACHE.get(key)
1148
+ if cached is None:
1149
+ cached = _run_host_inspect()
1150
+ _HOST_INSPECT_CACHE[key] = cached
1151
+ return cached
1152
+
1153
+
1154
+ def _inspect_component_row(
1155
+ repo_root: Path, host_id: str, component: str, label: str
1156
+ ) -> tuple[dict[str, object] | None, list[dict[str, str]] | None]:
1157
+ """The inspect row for one component, or the shared unavailable warning."""
1158
+ facts = _host_inspect_facts(repo_root)
1159
+ if not facts["available"]:
1160
+ return None, _host_inspect_unavailable_issue(host_id, facts)
1161
+ row = _inspect_row(facts, host_id, component)
1162
+ if row is None:
1163
+ return None, _host_inspect_unavailable_issue(
1164
+ host_id, {"reason": f"host inspect omitted {label}"}
1165
+ )
1166
+ return row, None
1167
+
1168
+
1169
+ def _unexpected_inspect_status(
1170
+ host_id: str, status: object
1171
+ ) -> list[dict[str, str]]:
1172
+ return _host_inspect_unavailable_issue(
1173
+ host_id, {"reason": f"host inspect reported status {status!r}"}
1174
+ )
1175
+
1176
+
1177
+ def _inspect_path(row: dict[str, object], fallback: str = "cowork-flow") -> Path:
1178
+ """The most specific path for a warning.
1179
+
1180
+ The read model owns host layout, so the doctor never derives the path from
1181
+ the human-readable reason: detail path, payload root, then registration."""
1182
+ return Path(
1183
+ str(
1184
+ row.get("detailPath")
1185
+ or row.get("payloadPath")
1186
+ or row.get("registeredSource")
1187
+ or fallback
1188
+ )
1189
+ )
1190
+
1191
+
1192
+ def _project_stale_message(
1193
+ subject: str, recorded: object, project_version: str, consequence: str
1194
+ ) -> str:
1195
+ return (
1196
+ f"{subject} was installed from {recorded or 'an unknown version'} but "
1197
+ f"this project runs {project_version}; {consequence}"
1198
+ )
1199
+
1200
+
1201
+ def _host_inspect_unavailable_issue(
1202
+ platform_id: str, facts: dict[str, object]
1203
+ ) -> list[dict[str, str]]:
1204
+ command = _host_inspect_command()
1205
+ label = " ".join(command) if command else "cwf"
1206
+ return [
1207
+ _issue(
1208
+ code="HOST-INSPECT-UNAVAILABLE",
1209
+ severity="warning",
1210
+ path=label,
1211
+ message=(
1212
+ f"cannot verify the {platform_id} plugin install state: "
1213
+ f"{facts.get('reason') or 'host inspect is unavailable'}; the "
1214
+ "installed cowork-flow CLI may be missing or older than this project"
1215
+ ),
1216
+ command_hint="npm install -g cowork-flow@latest",
1217
+ contract=_HOST_INSPECT_CONTRACT,
1218
+ )
1219
+ ]
1079
1220
 
1080
1221
 
1081
1222
  def check_qoder_plugin(repo_root: Path) -> list[dict[str, str]]:
1082
- """Qoder plugin health. Advisory, and silent while the project never
1083
- selected the Qoder host: the plugin is a machine-level asset installed once
1084
- into `~/.qoder/plugins`, so it never updates through sync or npm."""
1223
+ """Qoder plugin health from the CLI-owned install-state read model.
1224
+
1225
+ Advisory, and silent while the project never selected the Qoder host: the
1226
+ plugin is a machine-level asset installed once into `~/.qoder/plugins`, so
1227
+ it never updates through sync or npm."""
1085
1228
  adapter = repo_root / DIR_WORKFLOW / "adapters" / "qoder" / "adapter.yaml"
1086
1229
  if not adapter.is_file():
1087
1230
  return []
1088
1231
 
1089
- home = _qoder_home()
1090
- registry_path = home / "plugins" / "installed_plugins_v2.json"
1091
- entry = _qoder_registry_entry(registry_path)
1092
- if entry is None:
1232
+ row, unavailable = _inspect_component_row(
1233
+ repo_root, "qoder", "plugin", "qoder"
1234
+ )
1235
+ if unavailable is not None:
1236
+ return unavailable
1237
+ status = row.get("status")
1238
+ payload = Path(str(row.get("payloadPath") or row.get("registeredSource") or "qoder"))
1239
+ path = _inspect_path(row, "qoder")
1240
+ reason = str(row.get("reason") or "")
1241
+
1242
+ if status == "missing":
1093
1243
  return _qoder_warning(
1094
1244
  "PLUGIN-NOT-INSTALLED",
1095
- registry_path,
1245
+ path,
1096
1246
  "this project declares the Qoder host, but cowork-flow is not "
1097
1247
  "registered in the Qoder plugin cache, so Qoder sessions inject no "
1098
1248
  "workflow context; loading also needs a Qoder restart and a "
1099
1249
  "trusted workspace",
1100
1250
  "cwf host add qoder",
1101
1251
  )
1102
-
1103
- install_path = Path(str(entry.get("installPath") or ""))
1104
- manifest_relative = _payload_manifest("qoder", repo_root) or ".qoder-plugin/plugin.json"
1105
- if not (install_path / manifest_relative).is_file():
1252
+ if status == "broken":
1253
+ code = (
1254
+ "PLUGIN-PAYLOAD-MISSING"
1255
+ if "manifest" in reason or "installPath" in reason
1256
+ else "PLUGIN-PAYLOAD-INCOMPLETE"
1257
+ )
1106
1258
  return _qoder_warning(
1107
- "PLUGIN-PAYLOAD-MISSING",
1108
- install_path / manifest_relative,
1109
- f"the Qoder plugin registry points at {install_path}, but no "
1110
- "manifest is on disk there; the host cannot load a missing payload",
1259
+ code,
1260
+ path,
1261
+ f"the Qoder plugin at {payload} is incomplete ({reason}); the host "
1262
+ "cannot load it",
1111
1263
  "cwf host add qoder --force",
1112
1264
  )
1113
- for relative in ("hooks/hooks.json", "hooks/inject-context.mjs"):
1114
- if not (install_path / relative).is_file():
1265
+ if status in ("installed", "stale"):
1266
+ if row.get("enabled") is False:
1115
1267
  return _qoder_warning(
1116
- "PLUGIN-PAYLOAD-INCOMPLETE",
1117
- install_path / relative,
1118
- "the installed Qoder plugin has no hook payload, so every hook "
1119
- "command it declares fails to start",
1268
+ "PLUGIN-DISABLED",
1269
+ path,
1270
+ 'the Qoder plugin is installed but not enabled '
1271
+ f'(`enabledPlugins["{QODER_PLUGIN_KEY}"]`); no hook fires',
1120
1272
  "cwf host add qoder --force",
1121
1273
  )
1122
-
1123
- settings_path = home / "settings.json"
1124
- try:
1125
- settings = json.loads(settings_path.read_text(encoding="utf-8"))
1126
- except (OSError, json.JSONDecodeError, ValueError):
1127
- settings = {}
1128
- enabled = settings.get("enabledPlugins") if isinstance(settings, dict) else None
1129
- if not isinstance(enabled, dict) or enabled.get(QODER_PLUGIN_KEY) is not True:
1130
- return _qoder_warning(
1131
- "PLUGIN-DISABLED",
1132
- settings_path,
1133
- 'the Qoder plugin is installed but not enabled '
1134
- f'(`enabledPlugins["{QODER_PLUGIN_KEY}"]`); no hook fires',
1135
- "cwf host add qoder --force",
1136
- )
1137
-
1138
- recorded = str(entry.get("version") or "")
1139
- project_version = _project_version(repo_root)
1140
- if project_version and recorded != project_version:
1141
- return _qoder_warning(
1142
- "PLUGIN-STALE",
1143
- registry_path,
1144
- f"the Qoder plugin was installed from {recorded or 'an unknown version'} "
1145
- f"but this project runs {project_version}; the plugin does not update "
1146
- "with sync or npm, so injection may lag the project runtime",
1147
- "cwf host add qoder --force",
1148
- )
1149
- return []
1150
-
1151
-
1152
- _ZCODE_PLUGIN_CONTRACT = "runtime-health:zcode-plugin"
1153
-
1154
-
1155
- def _zcode_warning(code: str, path: Path, message: str, hint: str) -> list[dict[str, str]]:
1156
- return [
1157
- _issue(
1158
- code=code,
1159
- severity="warning",
1160
- path=str(path),
1161
- message=message,
1162
- command_hint=hint,
1163
- contract=_ZCODE_PLUGIN_CONTRACT,
1164
- )
1165
- ]
1166
-
1167
-
1168
- def _zcode_marketplace_path() -> Path:
1169
- home = Path(os.environ.get("ZCODE_HOME") or (Path.home() / ".zcode"))
1170
- return (
1171
- home
1172
- / "cli"
1173
- / "plugins"
1174
- / "marketplaces"
1175
- / "cowork-flow-local"
1176
- / "marketplace.json"
1177
- )
1274
+ project_version = _project_stale_version(row, repo_root)
1275
+ if project_version is not None:
1276
+ recorded = row.get("version") or "an unknown version"
1277
+ return _qoder_warning(
1278
+ "PLUGIN-STALE",
1279
+ path,
1280
+ _project_stale_message(
1281
+ "the Qoder plugin",
1282
+ recorded,
1283
+ project_version,
1284
+ "the plugin does not update with sync or npm, so injection "
1285
+ "may lag the project runtime",
1286
+ ),
1287
+ "cwf host add qoder --force",
1288
+ )
1289
+ return []
1290
+ return _unexpected_inspect_status("qoder", status)
1178
1291
 
1179
1292
 
1180
1293
  def check_zcode_plugin(repo_root: Path) -> list[dict[str, str]]:
1181
- """ZCode plugin health. Advisory, and silent while the project never selected
1182
- the ZCode host: the plugin is a machine-level asset installed once into the
1183
- ZCode config directory, so it never updates through sync or npm.
1294
+ """ZCode plugin health from the CLI-owned install-state read model.
1184
1295
 
1185
- Staleness is judged on the payload's stamped manifest version rather than
1186
- per file: the payload also carries a materialized copy of the project
1187
- runtime, and that copy may legitimately differ from this project."""
1296
+ Advisory, and silent while the project never selected the ZCode host: the
1297
+ plugin is a machine-level asset installed once into the ZCode config
1298
+ directory, so it never updates through sync or npm."""
1188
1299
  adapter = repo_root / DIR_WORKFLOW / "adapters" / "zcode" / "adapter.yaml"
1189
1300
  if not adapter.is_file():
1190
1301
  return []
1191
1302
 
1192
- marketplace = _zcode_marketplace_path()
1193
- payload = _machine_plugin_payload("zcode")
1194
- if payload is None:
1303
+ row, unavailable = _inspect_component_row(
1304
+ repo_root, "zcode", "plugin", "zcode"
1305
+ )
1306
+ if unavailable is not None:
1307
+ return unavailable
1308
+ status = row.get("status")
1309
+ payload = Path(str(row.get("payloadPath") or row.get("registeredSource") or "zcode"))
1310
+ path = _inspect_path(row, "zcode")
1311
+
1312
+ if status == "missing":
1195
1313
  return _zcode_warning(
1196
1314
  "PLUGIN-NOT-INSTALLED",
1197
- marketplace,
1315
+ path,
1198
1316
  "this project declares the ZCode host, but no cowork-flow plugin is "
1199
1317
  "installed in the ZCode config directory, so ZCode sessions inject no "
1200
1318
  "workflow context",
1201
1319
  "cwf host add zcode",
1202
1320
  )
1203
-
1204
- manifest_relative = _payload_manifest("zcode", repo_root) or ".zcode-plugin/plugin.json"
1205
- manifest = payload / manifest_relative
1206
- recorded = _marker_version(manifest)
1207
- if recorded is None:
1208
- return _zcode_warning(
1209
- "PLUGIN-UNKNOWN-VERSION",
1210
- manifest,
1211
- "the installed ZCode plugin carries no readable manifest version, so "
1212
- "its injection logic may predate the current release",
1213
- "cwf host add zcode --force",
1321
+ if status == "broken":
1322
+ reason = str(row.get("reason") or "")
1323
+ code = (
1324
+ "PLUGIN-UNKNOWN-VERSION"
1325
+ if "manifest" in reason or "no version" in reason
1326
+ else "PLUGIN-PAYLOAD-MISSING"
1214
1327
  )
1215
- project_version = _project_version(repo_root)
1216
- if project_version and recorded != project_version:
1217
1328
  return _zcode_warning(
1218
- "PLUGIN-STALE",
1219
- manifest,
1220
- f"the ZCode plugin was installed from {recorded} but this project "
1221
- f"runs {project_version}; the plugin does not update with sync or npm, "
1222
- "so injection may lag the project runtime",
1329
+ code,
1330
+ path,
1331
+ f"the ZCode plugin at {payload} is incomplete ({reason}); the host "
1332
+ "cannot load it",
1223
1333
  "cwf host add zcode --force",
1224
1334
  )
1225
- return []
1335
+ if status in ("installed", "stale"):
1336
+ project_version = _project_stale_version(row, repo_root)
1337
+ if project_version is not None:
1338
+ recorded = row.get("version") or "an unknown version"
1339
+ return _zcode_warning(
1340
+ "PLUGIN-STALE",
1341
+ path,
1342
+ _project_stale_message(
1343
+ "the ZCode plugin",
1344
+ recorded,
1345
+ project_version,
1346
+ "the plugin does not update with sync or npm, so injection "
1347
+ "may lag the project runtime",
1348
+ ),
1349
+ "cwf host add zcode --force",
1350
+ )
1351
+ return []
1352
+ return _unexpected_inspect_status("zcode", status)
1226
1353
 
1227
1354
 
1228
1355
  _CLAUDE_CODE_PLUGIN_CONTRACT = "runtime-health:claude-code-plugin"
1229
- _CLAUDE_CODE_PLUGIN_NAME = "cowork-flow"
1230
- _CLAUDE_CODE_SKILL = "skills/cowork-flow-bootstrap/SKILL.md"
1231
-
1232
-
1233
- def _claude_home() -> Path:
1234
- configured = (os.environ.get("CLAUDE_CONFIG_DIR") or "").strip()
1235
- return Path(configured) if configured else Path.home() / ".claude"
1236
1356
 
1237
1357
 
1238
1358
  def _claude_code_warning(
@@ -1263,62 +1383,56 @@ def check_claude_code_plugin(repo_root: Path) -> list[dict[str, str]]:
1263
1383
  if not adapter.is_file():
1264
1384
  return []
1265
1385
 
1266
- install_path = _claude_home() / "skills" / _CLAUDE_CODE_PLUGIN_NAME
1267
- manifest_relative = _payload_manifest(
1268
- "claude-code", repo_root
1269
- ) or ".claude-plugin/plugin.json"
1270
- manifest_path = install_path / manifest_relative
1271
- try:
1272
- manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
1273
- except (OSError, json.JSONDecodeError, ValueError):
1274
- manifest = None
1275
- if not isinstance(manifest, dict):
1386
+ row, unavailable = _inspect_component_row(
1387
+ repo_root, "claude-code", "plugin", "claude-code"
1388
+ )
1389
+ if unavailable is not None:
1390
+ return unavailable
1391
+ status = row.get("status")
1392
+ path = _inspect_path(row, "claude")
1393
+ reason = str(row.get("reason") or "")
1394
+
1395
+ if status == "missing":
1396
+ if reason == "a different plugin owns this directory":
1397
+ return []
1276
1398
  return _claude_code_warning(
1277
1399
  "PLUGIN-NOT-INSTALLED",
1278
- install_path,
1400
+ path,
1279
1401
  "this project declares the Claude Code host, but no cowork-flow "
1280
1402
  "skills-directory plugin is installed, so Claude Code sessions see "
1281
1403
  "no cowork-flow plugin Skill",
1282
1404
  "cwf host add claude-code",
1283
1405
  )
1284
- if manifest.get("name") != _CLAUDE_CODE_PLUGIN_NAME:
1285
- # A hand-made folder at the same path is not cowork-flow's to report on.
1286
- return []
1287
-
1288
- if not (install_path / _CLAUDE_CODE_SKILL).is_file():
1406
+ if status == "broken":
1289
1407
  return _claude_code_warning(
1290
1408
  "PLUGIN-PAYLOAD-INCOMPLETE",
1291
- install_path / _CLAUDE_CODE_SKILL,
1409
+ path,
1292
1410
  "the installed Claude Code plugin carries no bootstrap Skill, so it "
1293
1411
  "contributes nothing in a repository without a runtime",
1294
1412
  "cwf host add claude-code --force",
1295
1413
  )
1296
-
1297
- recorded = str(manifest.get("version") or "")
1298
- project_version = _project_version(repo_root)
1299
- if project_version and recorded != project_version:
1300
- return _claude_code_warning(
1301
- "PLUGIN-STALE",
1302
- manifest_path,
1303
- f"the Claude Code plugin was installed from {recorded or 'an unknown version'} "
1304
- f"but this project runs {project_version}; the plugin does not update "
1305
- "with sync or npm",
1306
- "cwf host add claude-code --force",
1307
- )
1308
- return []
1414
+ if status in ("installed", "stale"):
1415
+ project_version = _project_stale_version(row, repo_root)
1416
+ if project_version is not None:
1417
+ recorded = row.get("version") or "an unknown version"
1418
+ return _claude_code_warning(
1419
+ "PLUGIN-STALE",
1420
+ path,
1421
+ _project_stale_message(
1422
+ "the Claude Code plugin",
1423
+ recorded,
1424
+ project_version,
1425
+ "the plugin does not update with sync or npm",
1426
+ ),
1427
+ "cwf host add claude-code --force",
1428
+ )
1429
+ return []
1430
+ return _unexpected_inspect_status("claude-code", status)
1309
1431
 
1310
1432
 
1311
1433
  _OPENCODE_PLUGIN_CONTRACT = "runtime-health:opencode-plugin"
1312
- _OPENCODE_PLUGIN_FILE = "plugins/cowork-flow.js"
1313
- _OPENCODE_PLUGIN_MARKER = "CoworkFlowPlugin"
1314
- _OPENCODE_CORE = "cowork-flow/plugin-core.js"
1315
- _OPENCODE_SKILL = "cowork-flow/skills/cowork-flow-bootstrap/SKILL.md"
1316
-
1317
-
1318
- def _opencode_home() -> Path:
1319
- configured = (os.environ.get("XDG_CONFIG_HOME") or "").strip()
1320
- base = Path(configured) if configured else Path.home() / ".config"
1321
- return base / "opencode"
1434
+ _OPENCODE_PROJECT_PLUGIN = ".opencode/plugins/cowork-flow.js"
1435
+ _OPENCODE_PROJECT_CORE = ".opencode/cowork-flow/plugin-core.js"
1322
1436
 
1323
1437
 
1324
1438
  def _opencode_warning(
@@ -1337,10 +1451,11 @@ def _opencode_warning(
1337
1451
 
1338
1452
 
1339
1453
  def check_opencode_plugin(repo_root: Path) -> list[dict[str, str]]:
1340
- """OpenCode plugin health. Advisory, and silent while the project never
1341
- selected the OpenCode host: the plugin is a machine-level asset installed
1342
- once into the user's config directory, so it never updates through sync or
1343
- npm.
1454
+ """OpenCode plugin health from the CLI-owned install-state read model.
1455
+
1456
+ Advisory, and silent while the project never selected the OpenCode host: the
1457
+ plugin is a machine-level asset installed once into the user's config
1458
+ directory, so it never updates through sync or npm.
1344
1459
 
1345
1460
  OpenCode's plugin format carries no manifest, so there is no version to
1346
1461
  compare. Staleness is judged against the project's own copy of the same two
@@ -1350,63 +1465,65 @@ def check_opencode_plugin(repo_root: Path) -> list[dict[str, str]]:
1350
1465
  if not adapter.is_file():
1351
1466
  return []
1352
1467
 
1353
- home = _opencode_home()
1354
- plugin = home / _OPENCODE_PLUGIN_FILE
1355
- try:
1356
- installed = plugin.read_text(encoding="utf-8")
1357
- except OSError:
1468
+ row, unavailable = _inspect_component_row(
1469
+ repo_root, "opencode", "plugin", "opencode"
1470
+ )
1471
+ if unavailable is not None:
1472
+ return unavailable
1473
+ status = row.get("status")
1474
+ registered = Path(str(row.get("registeredSource") or "opencode"))
1475
+ payload = Path(str(row["payloadPath"])) if row.get("payloadPath") else registered
1476
+ path = _inspect_path(row, "opencode")
1477
+ reason = str(row.get("reason") or "")
1478
+
1479
+ if status == "missing":
1480
+ # A same-named file a user put there is not cowork-flow's to report on.
1481
+ if reason == "a different plugin owns this file":
1482
+ return []
1358
1483
  return _opencode_warning(
1359
1484
  "PLUGIN-NOT-INSTALLED",
1360
- plugin,
1485
+ path,
1361
1486
  "this project declares the OpenCode host, but no cowork-flow plugin "
1362
1487
  "is installed in the OpenCode config directory, so OpenCode sessions "
1363
1488
  "see no cowork-flow plugin Skill",
1364
1489
  "cwf host add opencode",
1365
1490
  )
1366
- if _OPENCODE_PLUGIN_MARKER not in installed:
1367
- # A same-named file a user put there is not cowork-flow's to report on.
1368
- return []
1369
-
1370
- for relative in (_OPENCODE_CORE, _OPENCODE_SKILL):
1371
- if not (home / relative).is_file():
1372
- return _opencode_warning(
1373
- "PLUGIN-PAYLOAD-INCOMPLETE",
1374
- home / relative,
1375
- f"the installed OpenCode plugin is missing {relative}, so it "
1376
- "registers a skills directory that is not there",
1377
- "cwf host add opencode --force",
1378
- )
1491
+ if status == "broken":
1492
+ return _opencode_warning(
1493
+ "PLUGIN-PAYLOAD-INCOMPLETE",
1494
+ path,
1495
+ f"the installed OpenCode plugin is incomplete ({reason}), so it "
1496
+ "registers a skills directory that is not there",
1497
+ "cwf host add opencode --force",
1498
+ )
1499
+ if status not in ("installed", "stale"):
1500
+ return _unexpected_inspect_status("opencode", status)
1379
1501
 
1380
- for relative in (_OPENCODE_PLUGIN_FILE, _OPENCODE_CORE):
1502
+ for installed_path, project_relative in (
1503
+ (registered, _OPENCODE_PROJECT_PLUGIN),
1504
+ (payload / "plugin-core.js", _OPENCODE_PROJECT_CORE),
1505
+ ):
1381
1506
  # A project mid-init has no copy yet; an unreadable one is not ours to
1382
1507
  # judge. Either way there is nothing to compare, so the loop moves on.
1383
1508
  try:
1384
- project_text = (repo_root / ".opencode" / relative).read_text(
1385
- encoding="utf-8"
1386
- )
1387
- installed_text = (
1388
- installed
1389
- if relative == _OPENCODE_PLUGIN_FILE
1390
- else (home / relative).read_text(encoding="utf-8")
1391
- )
1509
+ project_text = (repo_root / project_relative).read_text(encoding="utf-8")
1510
+ installed_text = installed_path.read_text(encoding="utf-8")
1392
1511
  except OSError:
1393
1512
  continue
1394
1513
  if project_text != installed_text:
1395
1514
  return _opencode_warning(
1396
1515
  "PLUGIN-STALE",
1397
- home / relative,
1398
- f"the installed OpenCode {relative} differs from this project's "
1399
- "copy of the same file; one of them was updated and the other "
1400
- "was not, and the plugin does not update with sync or npm",
1516
+ installed_path,
1517
+ f"the installed OpenCode {project_relative} differs from this "
1518
+ "project's copy of the same file; one of them was updated and "
1519
+ "the other was not, and the plugin does not update with sync or "
1520
+ "npm",
1401
1521
  "cwf host add opencode --force",
1402
1522
  )
1403
1523
  return []
1404
1524
 
1405
1525
 
1406
1526
  _KIMI_PLUGIN_CONTRACT = "runtime-health:kimi-code-plugin"
1407
- _KIMI_PLUGIN_NAME = "cowork-flow"
1408
- _KIMI_PLUGIN_MANIFEST = ".kimi-plugin/plugin.json"
1409
- _KIMI_PLUGIN_SKILL = "skills/cowork-flow-bootstrap/SKILL.md"
1410
1527
 
1411
1528
 
1412
1529
  def _kimi_plugin_warning(
@@ -1424,28 +1541,10 @@ def _kimi_plugin_warning(
1424
1541
  ]
1425
1542
 
1426
1543
 
1427
- def _kimi_plugin_record(home: Path) -> dict | None:
1428
- """The registry entry for cowork-flow, or None. Kimi Code keeps one record per
1429
- plugin in plugins/installed.json; an unreadable or unexpected file means the
1430
- same thing to this check as an absent record."""
1431
- try:
1432
- data = json.loads(
1433
- (home / "plugins" / "installed.json").read_text(encoding="utf-8")
1434
- )
1435
- except (OSError, json.JSONDecodeError, ValueError):
1436
- return None
1437
- plugins = data.get("plugins") if isinstance(data, dict) else None
1438
- if not isinstance(plugins, list):
1439
- return None
1440
- for entry in plugins:
1441
- if isinstance(entry, dict) and entry.get("id") == _KIMI_PLUGIN_NAME:
1442
- return entry
1443
- return None
1444
-
1445
-
1446
1544
  def check_kimi_code_plugin(repo_root: Path) -> list[dict[str, str]]:
1447
- """Kimi Code plugin health. Advisory, and silent while the project never
1448
- selected the Kimi Code host.
1545
+ """Kimi Code plugin health from the CLI-owned install-state read model.
1546
+
1547
+ Advisory, and silent while the project never selected the Kimi Code host.
1449
1548
 
1450
1549
  The plugin is a machine-level asset: `cwf host add kimi-code` installs the
1451
1550
  managed copy and writes the registry record itself (no TUI handoff), so a
@@ -1455,60 +1554,60 @@ def check_kimi_code_plugin(repo_root: Path) -> list[dict[str, str]]:
1455
1554
  if not adapter.is_file():
1456
1555
  return []
1457
1556
 
1458
- home = _kimi_home()
1459
- record = _kimi_plugin_record(home)
1460
- if record is None:
1557
+ row, unavailable = _inspect_component_row(
1558
+ repo_root, "kimi-code", "plugin", "kimi-code"
1559
+ )
1560
+ if unavailable is not None:
1561
+ return unavailable
1562
+ status = row.get("status")
1563
+ path = _inspect_path(row, "kimi-code")
1564
+ reason = str(row.get("reason") or "")
1565
+
1566
+ if status == "missing":
1461
1567
  return _kimi_plugin_warning(
1462
1568
  "PLUGIN-NOT-INSTALLED",
1463
- home / "plugins" / "installed.json",
1569
+ path,
1464
1570
  "this project declares the Kimi Code host, but cowork-flow is not "
1465
1571
  "registered as a Kimi Code plugin, so sessions load no cowork-flow "
1466
1572
  "plugin Skill",
1467
1573
  "cwf host add kimi-code",
1468
1574
  )
1469
- if record.get("enabled") is False:
1575
+ if row.get("enabled") is False:
1470
1576
  return _kimi_plugin_warning(
1471
1577
  "PLUGIN-DISABLED",
1472
- home / "plugins" / "installed.json",
1578
+ path,
1473
1579
  "the cowork-flow Kimi Code plugin is installed but disabled, so its "
1474
1580
  "bootstrap Skill never loads",
1475
1581
  "/plugins enable cowork-flow",
1476
1582
  )
1477
-
1478
- recorded_root = str(record.get("root") or "")
1479
- root = Path(recorded_root) if recorded_root else home / "plugins" / "managed" / _KIMI_PLUGIN_NAME
1480
- for relative in (_KIMI_PLUGIN_MANIFEST, _KIMI_PLUGIN_SKILL):
1481
- if not (root / relative).is_file():
1482
- return _kimi_plugin_warning(
1483
- "PLUGIN-PAYLOAD-INCOMPLETE",
1484
- root / relative,
1485
- f"the installed Kimi Code plugin is missing {relative}, so it "
1486
- "cannot load the bootstrap Skill",
1487
- "cwf host add kimi-code --force",
1488
- )
1489
-
1490
- try:
1491
- recorded_version = json.loads(
1492
- (root / _KIMI_PLUGIN_MANIFEST).read_text(encoding="utf-8")
1493
- ).get("version")
1494
- except (OSError, json.JSONDecodeError, ValueError, AttributeError):
1495
- recorded_version = None
1496
- project_version = _project_version(repo_root)
1497
- if project_version and recorded_version != project_version:
1583
+ if status == "broken":
1584
+ return _kimi_plugin_warning(
1585
+ "PLUGIN-PAYLOAD-INCOMPLETE",
1586
+ path,
1587
+ f"the installed Kimi Code plugin is incomplete ({reason}), so it "
1588
+ "cannot load the bootstrap Skill",
1589
+ "cwf host add kimi-code --force",
1590
+ )
1591
+ if status not in ("installed", "stale"):
1592
+ return _unexpected_inspect_status("kimi-code", status)
1593
+ project_version = _project_stale_version(row, repo_root)
1594
+ if project_version is not None:
1595
+ recorded = row.get("version") or "an unknown version"
1498
1596
  return _kimi_plugin_warning(
1499
1597
  "PLUGIN-STALE",
1500
- root / _KIMI_PLUGIN_MANIFEST,
1501
- f"the Kimi Code plugin was installed from "
1502
- f"{recorded_version or 'an unknown version'} but this project runs "
1503
- f"{project_version}; the plugin does not update with sync or npm",
1598
+ path,
1599
+ _project_stale_message(
1600
+ "the Kimi Code plugin",
1601
+ recorded,
1602
+ project_version,
1603
+ "the plugin does not update with sync or npm",
1604
+ ),
1504
1605
  "cwf host add kimi-code --force",
1505
1606
  )
1506
-
1507
- source = home / "plugins" / "sources" / _KIMI_PLUGIN_NAME
1508
- if not source.is_dir():
1607
+ if reason == "stable reinstall source directory is missing":
1509
1608
  return _kimi_plugin_warning(
1510
1609
  "PLUGIN-SOURCES-MISSING",
1511
- source,
1610
+ path,
1512
1611
  "the cowork-flow Kimi Code plugin is registered but its stable "
1513
1612
  "reinstall source directory is gone",
1514
1613
  "cwf host add kimi-code",
@@ -1518,7 +1617,6 @@ def check_kimi_code_plugin(repo_root: Path) -> list[dict[str, str]]:
1518
1617
 
1519
1618
  _CODEX_PLUGIN_CONTRACT = "runtime-health:codex-plugin"
1520
1619
  CODEX_PLUGIN_KEY = "cowork-flow@cowork-flow-local"
1521
- _CODEX_MARKETPLACE = "cowork-flow-local"
1522
1620
 
1523
1621
 
1524
1622
  def _codex_warning(code: str, path: Path, message: str, hint: str) -> list[dict[str, str]]:
@@ -1534,92 +1632,67 @@ def _codex_warning(code: str, path: Path, message: str, hint: str) -> list[dict[
1534
1632
  ]
1535
1633
 
1536
1634
 
1537
- def _codex_home() -> Path:
1538
- configured = (os.environ.get("CODEX_HOME") or "").strip()
1539
- return Path(configured) if configured else Path.home() / ".codex"
1540
-
1541
-
1542
- def _codex_config_sections(config_path: Path) -> dict[str, dict[str, str]]:
1543
- """Flat key/value pairs for the two sections cowork-flow owns.
1544
-
1545
- The CI floor is Python 3.10, which has no tomllib, and a TOML dependency is
1546
- not worth two flat sections: every other line and section stays unread.
1547
- """
1548
- try:
1549
- text = config_path.read_text(encoding="utf-8")
1550
- except OSError:
1551
- return {}
1552
- wanted = {
1553
- f"marketplaces.{_CODEX_MARKETPLACE}",
1554
- f"plugins.{CODEX_PLUGIN_KEY}",
1555
- }
1556
- sections: dict[str, dict[str, str]] = {}
1557
- current: dict[str, str] | None = None
1558
- for raw in text.splitlines():
1559
- line = raw.strip()
1560
- if not line or line.startswith("#"):
1561
- continue
1562
- if line.startswith("[") and line.endswith("]"):
1563
- name = line[1:-1].strip().replace('"', "")
1564
- current = sections.setdefault(name, {}) if name in wanted else None
1565
- continue
1566
- if current is None or "=" not in line:
1567
- continue
1568
- key, _, value = line.partition("=")
1569
- current[key.strip().strip('"').strip("'")] = value.strip().strip('"').strip("'")
1570
- return sections
1571
-
1572
-
1573
- def _codex_marketplace_source() -> str:
1574
- """Marketplace source path registered in the Codex config, or ""."""
1575
- sections = _codex_config_sections(_codex_home() / "config.toml")
1576
- return sections.get(f"marketplaces.{_CODEX_MARKETPLACE}", {}).get("source", "")
1577
-
1578
-
1579
1635
  def check_codex_plugin(repo_root: Path) -> list[dict[str, str]]:
1580
- """Codex plugin health. Advisory, and silent while the project never
1581
- selected the Codex host: the plugin is a machine-level asset registered in
1582
- `~/.codex/config.toml`, so it never updates through sync or npm."""
1636
+ """Codex plugin health from the CLI-owned install-state read model.
1637
+
1638
+ Advisory, and silent while the project never selected the Codex host: the
1639
+ plugin is a machine-level asset registered in `~/.codex/config.toml`, so it
1640
+ never updates through sync or npm."""
1583
1641
  adapter = repo_root / DIR_WORKFLOW / "adapters" / "codex" / "adapter.yaml"
1584
1642
  if not adapter.is_file():
1585
1643
  return []
1586
1644
 
1587
- config_path = _codex_home() / "config.toml"
1588
- sections = _codex_config_sections(config_path)
1589
- marketplace = sections.get(f"marketplaces.{_CODEX_MARKETPLACE}")
1590
- if not marketplace:
1645
+ row, unavailable = _inspect_component_row(
1646
+ repo_root, "codex", "plugin", "codex"
1647
+ )
1648
+ if unavailable is not None:
1649
+ return unavailable
1650
+ status = row.get("status")
1651
+ path = _inspect_path(row, "codex")
1652
+ reason = str(row.get("reason") or "")
1653
+
1654
+ if status == "missing":
1591
1655
  return _codex_warning(
1592
1656
  "PLUGIN-NOT-INSTALLED",
1593
- config_path,
1657
+ path,
1594
1658
  "this project declares the Codex host, but cowork-flow's marketplace "
1595
1659
  "is not registered in the Codex config, so Codex sessions see no "
1596
1660
  "cowork-flow plugin Skills",
1597
1661
  "cwf host add codex",
1598
1662
  )
1599
-
1600
- source = marketplace.get("source", "")
1601
- payload = (Path(source) / "plugins" / "cowork-flow") if source else None
1602
- manifest_relative = _payload_manifest("codex", repo_root) or ".codex-plugin/plugin.json"
1603
- if payload is None or not (payload / manifest_relative).is_file():
1663
+ if status == "broken":
1604
1664
  return _codex_warning(
1605
1665
  "PLUGIN-PAYLOAD-MISSING",
1606
- payload if payload is not None else config_path,
1607
- f"the Codex marketplace is registered from {source or 'an unknown path'}, "
1608
- "but no plugin manifest is on disk there; the host cannot load a "
1609
- "missing payload",
1666
+ path,
1667
+ f"the Codex marketplace is registered but its payload is incomplete "
1668
+ f"({reason}); the host cannot load a missing payload",
1610
1669
  "cwf host add codex --force",
1611
1670
  )
1612
-
1613
- plugin = sections.get(f"plugins.{CODEX_PLUGIN_KEY}")
1614
- if not plugin or plugin.get("enabled") != "true":
1671
+ if status not in ("installed", "stale"):
1672
+ return _unexpected_inspect_status("codex", status)
1673
+ if row.get("enabled") is not True:
1615
1674
  return _codex_warning(
1616
1675
  "PLUGIN-DISABLED",
1617
- config_path,
1676
+ path,
1618
1677
  "the Codex plugin is registered but not enabled "
1619
1678
  f'(`[plugins."{CODEX_PLUGIN_KEY}"] enabled = true`), so its Skills '
1620
1679
  "stay invisible to sessions",
1621
1680
  "cwf host add codex --force",
1622
1681
  )
1682
+ project_version = _project_stale_version(row, repo_root)
1683
+ if project_version is not None:
1684
+ recorded = row.get("version") or "an unknown version"
1685
+ return _codex_warning(
1686
+ "PLUGIN-STALE",
1687
+ path,
1688
+ _project_stale_message(
1689
+ "the Codex plugin",
1690
+ recorded,
1691
+ project_version,
1692
+ "the plugin does not update with sync or npm",
1693
+ ),
1694
+ "cwf host add codex --force",
1695
+ )
1623
1696
  return []
1624
1697
 
1625
1698
 
@@ -1641,49 +1714,20 @@ def _skill_delivery_warning(
1641
1714
  ]
1642
1715
 
1643
1716
 
1644
- def _machine_plugin_payload(platform_id: str) -> Path | None:
1645
- """Payload root of a host's machine-level plugin, or None when that host
1646
- keeps no readable install. Mirrors where the install commands write."""
1647
- if platform_id == "qoder":
1648
- entry = _qoder_registry_entry(
1649
- _qoder_home() / "plugins" / "installed_plugins_v2.json"
1650
- )
1651
- payload = Path(str(entry.get("installPath") or "")) if entry else None
1652
- return payload if payload is not None and payload.is_dir() else None
1653
- if platform_id == "zcode":
1654
- marketplace = _zcode_marketplace_path()
1655
- try:
1656
- data = json.loads(marketplace.read_text(encoding="utf-8"))
1657
- except (OSError, json.JSONDecodeError, ValueError):
1658
- return None
1659
- plugins = data.get("plugins") if isinstance(data, dict) else None
1660
- for plugin in plugins if isinstance(plugins, list) else ():
1661
- source = plugin.get("source") if isinstance(plugin, dict) else None
1662
- path = source.get("path") if isinstance(source, dict) else None
1663
- payload = Path(str(path)) if path else None
1664
- if payload is not None and payload.is_dir():
1665
- return payload
1666
- return None
1667
- if platform_id == "codex":
1668
- source = _codex_marketplace_source()
1669
- if not source:
1670
- return None
1671
- payload = Path(source) / "plugins" / "cowork-flow"
1672
- return payload if payload.is_dir() else None
1673
- return None
1674
-
1675
-
1676
1717
  def _legacy_machine_skills_issues(
1677
- platform_id: str, project_skills: Path | None
1718
+ platform_id: str,
1719
+ project_skills: Path | None,
1720
+ facts: dict[str, object],
1678
1721
  ) -> list[dict[str, str]]:
1679
1722
  """Warnings for a host whose machine-level plugin still carries a copy of a
1680
1723
  Skill this project also ships. The payload is bootstrap-only, so a
1681
1724
  same-named copy is a leftover that may come from another release; a payload
1682
1725
  Skill the project does not ship (the bootstrap guide) is expected and stays
1683
1726
  silent."""
1684
- payload = _machine_plugin_payload(platform_id)
1685
- if payload is None:
1727
+ row = _inspect_row(facts, platform_id, "plugin")
1728
+ if row is None or not row.get("payloadPath"):
1686
1729
  return []
1730
+ payload = Path(str(row["payloadPath"]))
1687
1731
  skills = payload / "skills"
1688
1732
  if not skills.is_dir():
1689
1733
  return []
@@ -1731,7 +1775,10 @@ def check_skill_delivery(repo_root: Path) -> list[dict[str, str]]:
1731
1775
  platforms = detect_installed_platforms(repo_root)
1732
1776
  except HostManifestError:
1733
1777
  return []
1778
+ if not platforms:
1779
+ return []
1734
1780
  issues: list[dict[str, str]] = []
1781
+ facts = _host_inspect_facts(repo_root)
1735
1782
  for platform_id in platforms:
1736
1783
  platform = manifest.platform(platform_id)
1737
1784
  read_root = repo_root / platform.skill_read_root
@@ -1761,7 +1808,9 @@ def check_skill_delivery(repo_root: Path) -> list[dict[str, str]]:
1761
1808
  )
1762
1809
  )
1763
1810
  issues.extend(
1764
- _legacy_machine_skills_issues(platform_id, read_root if delivered else None)
1811
+ _legacy_machine_skills_issues(
1812
+ platform_id, read_root if delivered else None, facts
1813
+ )
1765
1814
  )
1766
1815
  return issues
1767
1816