@passioncode-ai/fabric-agent-adapter 0.39.0 → 0.40.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 (115) hide show
  1. package/CHANGELOG.md +126 -1
  2. package/README.md +25 -17
  3. package/bin/fabric-agent-adapter.js +6 -6
  4. package/package.json +1 -1
  5. package/plugins/fabric-agent-adapter/.claude-plugin/plugin.json +1 -1
  6. package/plugins/fabric-agent-adapter/skills/adapting-projects-to-fabric/SKILL.md +13 -13
  7. package/plugins/fabric-agent-adapter/skills/adapting-projects-to-fabric/references/dashboard-links.md +1 -1
  8. package/plugins/fabric-agent-adapter/skills/adapting-projects-to-fabric/references/provider-entry.md +4 -4
  9. package/plugins/fabric-agent-adapter/skills/building-fabric-services/SKILL.md +56 -45
  10. package/plugins/fabric-agent-adapter/skills/building-fabric-services/assets/dashboard-kit/demo.html +1 -1
  11. package/plugins/fabric-agent-adapter/skills/building-fabric-services/assets/dashboard-kit/fabric-button.js +3 -3
  12. package/plugins/fabric-agent-adapter/skills/building-fabric-services/assets/dashboard-kit/fabric-dashboard.css +1 -1
  13. package/plugins/fabric-agent-adapter/skills/building-fabric-services/assets/dashboard-kit/fabric-dashboard.js +2 -2
  14. package/plugins/fabric-agent-adapter/skills/building-fabric-services/assets/dashboard-kit/kit.json +9 -4
  15. package/plugins/fabric-agent-adapter/skills/building-fabric-services/recipes/support-agent/README.md +64 -0
  16. package/plugins/fabric-agent-adapter/skills/building-fabric-services/recipes/support-agent/config.example.json +15 -0
  17. package/plugins/fabric-agent-adapter/skills/building-fabric-services/recipes/support-agent/knowledge.example.json +13 -0
  18. package/plugins/fabric-agent-adapter/skills/building-fabric-services/recipes/support-agent/support_agent.py +264 -0
  19. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/board.md +12 -12
  20. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/connectors.md +93 -0
  21. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/dashboard-kit.md +4 -4
  22. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/dashboard-links.md +1 -1
  23. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/dashboard.md +4 -4
  24. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/delegation.md +13 -11
  25. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/estate-record.md +11 -5
  26. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/events-and-notifications.md +6 -6
  27. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/interop.md +8 -6
  28. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/kit-modules.md +128 -0
  29. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/lifecycle.md +26 -26
  30. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/migrating-a-service.md +1 -1
  31. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/package.md +3 -2
  32. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/profiles.md +10 -10
  33. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/protocol.md +13 -13
  34. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/remote-placement.md +4 -4
  35. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/settings-backups.md +3 -3
  36. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/surfaces-and-auth.md +5 -5
  37. package/plugins/fabric-agent-adapter/skills/building-fabric-services/references/usage.md +7 -4
  38. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/check_service.py +11 -209
  39. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/check_service_rules.py +204 -0
  40. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/dashboard_kit.py +1 -1
  41. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-auth.mjs +286 -0
  42. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-backups.mjs +327 -0
  43. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-base.mjs +47 -0
  44. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-board-fixture.mjs +79 -0
  45. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-board-session.mjs +840 -0
  46. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-board-shapes.mjs +340 -0
  47. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-board.mjs +42 -1237
  48. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-ceremonies.mjs +1 -16
  49. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-crypto.mjs +41 -0
  50. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-delegation.mjs +15 -46
  51. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-descriptor.mjs +387 -0
  52. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-estate.mjs +8 -67
  53. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-events.mjs +52 -0
  54. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-http.mjs +231 -0
  55. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-interop.mjs +2 -2
  56. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-jsvalue.mjs +67 -0
  57. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-lock.mjs +202 -0
  58. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-logs.mjs +136 -0
  59. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-openrouter.mjs +335 -0
  60. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-package.mjs +3 -13
  61. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-paths.mjs +69 -0
  62. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-platform.mjs +164 -0
  63. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-profiles.mjs +1 -32
  64. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-protocols.mjs +122 -0
  65. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-service.mjs +177 -2521
  66. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-share.mjs +1 -8
  67. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-supervisors.mjs +400 -0
  68. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-time.mjs +46 -0
  69. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric-usage.mjs +458 -0
  70. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_auth.py +402 -0
  71. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_backups.py +399 -0
  72. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_base.py +78 -0
  73. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_board.py +64 -1398
  74. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_board_fixture.py +116 -0
  75. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_board_session.py +902 -0
  76. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_board_shapes.py +457 -0
  77. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_ceremonies.py +36 -38
  78. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_crypto.py +289 -0
  79. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_delegation.py +16 -181
  80. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_descriptor.py +586 -0
  81. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_estate.py +39 -400
  82. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_events.py +137 -0
  83. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_http.py +402 -0
  84. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_interop.py +1 -6
  85. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_jsvalue.py +310 -0
  86. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_kit.py +243 -0
  87. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_lock.py +308 -0
  88. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_logs.py +202 -0
  89. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_openrouter.py +431 -0
  90. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_package.py +22 -44
  91. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_paths.py +102 -0
  92. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_platform.py +338 -0
  93. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_profiles.py +31 -38
  94. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_protocols.py +173 -0
  95. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_service.py +298 -3430
  96. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_share.py +8 -8
  97. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_supervisors.py +412 -0
  98. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_time.py +120 -0
  99. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/fabric_usage.py +697 -0
  100. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/kit.json +1526 -0
  101. package/plugins/fabric-agent-adapter/skills/building-fabric-services/scripts/sample_service.py +1 -1
  102. package/plugins/fabric-agent-adapter/skills/creating-fabric-agents/SKILL.md +33 -33
  103. package/plugins/fabric-agent-adapter/skills/creating-fabric-agents/references/dashboard-links.md +1 -1
  104. package/plugins/fabric-agent-adapter/skills/creating-fabric-agents/references/models-and-providers.md +3 -0
  105. package/plugins/fabric-agent-adapter/skills/creating-fabric-agents/references/resilience-and-autonomy.md +27 -27
  106. package/plugins/fabric-agent-adapter/skills/working-with-fabric/SKILL.md +31 -31
  107. package/plugins/fabric-agent-adapter/skills/working-with-fabric/references/project-board.md +9 -9
  108. package/plugins/fabric-agent-adapter/skills/working-with-fabric/references/session-hooks.md +8 -8
  109. package/plugins/fabric-agent-adapter/skills/working-with-fabric/scripts/fabric_session.py +116 -1392
  110. package/plugins/fabric-agent-adapter/skills/working-with-fabric/scripts/fabric_session_cli.py +270 -0
  111. package/plugins/fabric-agent-adapter/skills/working-with-fabric/scripts/fabric_session_env.py +508 -0
  112. package/plugins/fabric-agent-adapter/skills/working-with-fabric/scripts/fabric_session_hosts.py +265 -0
  113. package/plugins/fabric-agent-adapter/skills/working-with-fabric/scripts/fabric_session_mail.py +155 -0
  114. package/plugins/fabric-agent-adapter/skills/working-with-fabric/scripts/fabric_session_mcp.py +335 -0
  115. package/plugins/fabric-agent-adapter/skills/working-with-fabric/scripts/host_hooks.py +1 -0
@@ -16,13 +16,13 @@
16
16
  the estate's delegation tokens; declare `auth.delegation {issuer, jwks}` in the well-known
17
17
  document. The probe treats it like `own` and checks the declaration
18
18
  (`auth.delegation-declared`). The kits verify the tokens: put `delegation_gate` /
19
- `delegationGate` in front of the tools — see [the delegation reference](delegation.md).
19
+ `delegationGate` in front of the tools (see [the delegation reference](delegation.md)).
20
20
  - Register it into a client config with the service's own command
21
21
  (`<tool> mcp-register`), which writes `{"type":"http","url":"http://127.0.0.1:<port>/mcp","headers":{...}}`
22
22
  atomically, aborts if the file changed meanwhile, and keeps one 0600 backup. The token
23
- goes in `headers`, never in the URL — every log that records a URL prints its query
23
+ goes in `headers`, never in the URL: every log that records a URL prints its query
24
24
  string. An HTTP registration starts nothing per session: every client session talks to the
25
- one resident service (LC-19). A stdio server, by contrast, is a process per session — keep
25
+ one resident service (LC-19). A stdio server, by contrast, is a process per session; keep
26
26
  one only at project scope.
27
27
  - Ship server `instructions` that tell a caller where to start and that every answer
28
28
  carries `degraded`.
@@ -39,7 +39,7 @@ a sign-in link only when stdout is a terminal.
39
39
  ## A2A for remote agents
40
40
 
41
41
  Remote reach goes through A2A `1.0` over HTTPS or an authenticated gateway in front of
42
- MCP — never by binding a LAN address. A tunnel (Tailscale Serve and the like) is an
42
+ MCP, never by binding a LAN address. A tunnel (Tailscale Serve and the like) is an
43
43
  outward surface with its own token lifetime; watch it like a service, because nothing
44
44
  else will notice it expire.
45
45
 
@@ -50,7 +50,7 @@ else will notice it expire.
50
50
  - Compared in constant time (`token_matches`).
51
51
  - Rotation is an operator act: write a new file, restart, re-run `mcp-register`.
52
52
  - Same-user processes can read it. The protocol defends against web pages and
53
- mistakes, not against hostile code running as the operator — say so in SECURITY.md.
53
+ mistakes, not against hostile code running as the operator; say so in SECURITY.md.
54
54
 
55
55
  ## Dashboard session
56
56
 
@@ -1,4 +1,4 @@
1
- # Usage report — what the agent spent (DEC-0021)
1
+ # Usage report: what the agent spent (DEC-0021)
2
2
 
3
3
  Fabric Agent Contract DEC-0021, `docs/specification/service.md` → *Usage report*, schema
4
4
  `schemas/service-usage.schema.json`. Optional. A service that calls paid models or tools should
@@ -29,6 +29,8 @@ ledger.record(receipt) # fs.JsonlUsageLedger(data / "usage.j
29
29
  ledger.record(k.makeUsageReceipt('openrouter', model, { inputTokens, outputTokens, costUsd: usage.cost ?? null }));
30
30
  ```
31
31
 
32
+ - **OpenRouter through the kit.** `fabric_openrouter.Client` records these receipts itself, one per answered call,
33
+ and checks a spend ceiling before every attempt ([connectors](connectors.md)).
32
34
  - **The provider's own numbers.** Take tokens from the response's usage block, not from a local
33
35
  estimate. The cost is `provider` when the provider reported the charge (OpenRouter `usage.cost`,
34
36
  a billing API) and `price-list` when you computed it from a published price list.
@@ -39,7 +41,8 @@ ledger.record(k.makeUsageReceipt('openrouter', model, { inputTokens, outputToken
39
41
  - **Unknown tokens are named too** (DEC-0091). When the provider gave no token count (a stream cut off, a local
40
42
  model without a counter), pass `tokens_measured=False` / `tokensMeasured: false` with the tokens you have (often 0).
41
43
  The receipt carries `tokensMeasured: false`, and the report counts the call in `unmeasuredCalls` on its day and model
42
- row, never more than `calls`; a host then shows the token totals as a lower bound.
44
+ row, never more than `calls`; a host then shows the token totals as a lower bound. A job whose usage you send as
45
+ `null` or `partial` ([interop](interop.md)) is such a call.
43
46
  - **No content.** A receipt carries no prompt, output, caller or user id. The kits accept only the
44
47
  fields above.
45
48
  - If the service already keeps a ledger (a jobs table with token counts), build the receipts from
@@ -63,7 +66,7 @@ left out.
63
66
  it, and the host only shows it.
64
67
 
65
68
  **Every limit (DEC-0027).** Pass `budgets` to list every spending limit the service applies,
66
- enforced or not, so the spend view shows all of them — the operator asked for that on 2026-10-07:
69
+ enforced or not, so the spend view shows all of them; the operator asked for that on 2026-10-07:
67
70
 
68
71
  ```python
69
72
  ledger.report(service_id=ID, budget={"period": "month", "limitUsd": 100}, budgets=[
@@ -78,7 +81,7 @@ ledger.report(service_id=ID, budget={"period": "month", "limitUsd": 100}, budget
78
81
  way `budget` is, so `budget` and its twin in `budgets` never disagree. A per-order limit
79
82
  (`per_job`, `approval`) gets `spentUsd: null`. Every other limit states its own spend.
80
83
  - `scope` is `machine`, `project`, `pool` or `job`; a `project` or `pool` limit names its
81
- `subject`. A limit has at most one window — `period`, `windowSeconds` or `since` — and it agrees
84
+ `subject`. A limit has at most one window (`period`, `windowSeconds` or `since`), and it agrees
82
85
  with the kind (`daily`: the day or 86400 s; `monthly`: the month or 28–31 days; `velocity`: a
83
86
  rolling window). `tripped: true` (work stopped by it now) needs `enforced: true`. An unknown
84
87
  kind is shown generically, never refused.
@@ -57,74 +57,16 @@ import fabric_interop as fi # noqa: E402
57
57
  Result = Dict[str, str]
58
58
 
59
59
 
60
-
61
- def plist_problems(plist: dict, label: object, token: object = None) -> list:
62
- """What makes a service's launchd job unfit to stay up: identity, restart, secrets."""
63
- problems = []
64
- if plist.get("Label") != label:
65
- problems.append("Label %r" % plist.get("Label"))
66
- if plist.get("RunAtLoad") is not True:
67
- problems.append("RunAtLoad is not true")
68
- if plist.get("KeepAlive") is not True:
69
- problems.append("KeepAlive is %r, not true" % plist.get("KeepAlive"))
70
- for key, value in (plist.get("EnvironmentVariables") or {}).items():
71
- if re.search(r"(TOKEN|SECRET|PASSWORD|KEY)$", key) and not key.endswith("_FILE"):
72
- problems.append("secret-like variable %s in the plist" % key)
73
- if token and token in str(value):
74
- problems.append("the service token itself is in the plist")
75
- return problems
76
-
77
-
78
- def marker_problem(plist: dict) -> Optional[str]:
79
- """What is wrong with the job's supervisor marker (DEC-0057; FAA-05), read the way the copy it starts reads it.
80
-
81
- Without ``FABRIC_SERVICE_SUPERVISOR=launchd`` (or ``--fabric-supervisor launchd``) a copy that finds the
82
- lock held exits 75 at once, and KeepAlive starts it again every ThrottleInterval."""
83
- env = plist.get("EnvironmentVariables")
84
- env = {str(k): str(v) for k, v in env.items()} if isinstance(env, dict) else {}
85
- argv = plist.get("ProgramArguments")
86
- argv = [str(a) for a in argv] if isinstance(argv, list) else []
87
- marker = fs.supervisor_marker(env, argv)
88
- if marker["kind"] == "supervised" and marker["manager"] == "launchd":
89
- return None
90
- fix = ("a copy that finds the lock held exits 75 at once and KeepAlive respawns it every ThrottleInterval; "
91
- "regenerate the plist with launchd_plist / launchdPlist and reinstall")
92
- if marker["kind"] == "conflict":
93
- return "%s — %s" % (fs.marker_conflict_message(marker), fix)
94
- if marker["kind"] == "supervised":
95
- return "the marker names %s, not launchd — %s" % (marker["manager"], fix)
96
- if marker.get("unreadable") is not None:
97
- return "the marker %r names no supervisor — %s" % (marker["unreadable"], fix)
98
- return "no %s=launchd — %s" % (fs.SUPERVISOR_ENV, fix)
99
-
100
-
101
- def priority_problems(plist: dict) -> list:
102
- """A service that answers hosts and agents must not be scheduled as background work."""
103
- out = []
104
- if plist.get("ProcessType", "Standard") in ("Background", "Adaptive"):
105
- out.append("ProcessType is %s" % plist.get("ProcessType"))
106
- if isinstance(plist.get("Nice"), int) and plist["Nice"] > 0:
107
- out.append("Nice is %d" % plist["Nice"])
108
- if plist.get("LowPriorityIO") is True or plist.get("LowPriorityBackgroundIO") is True:
109
- out.append("low-priority I/O")
110
- return out
111
-
112
-
113
- # A platform router (Heroku, Fly, Render, a CDN) routes by Host, so a request naming a foreign
114
- # Host never reaches an online service: the router itself answers, typically 404 or 421. That is
115
- # still a refusal — the service disclosed nothing — so for a remote placement the host check
116
- # accepts it, as long as the body is not the well-known document. Every other guard request names
117
- # the right Host, reaches the service, and must be the service's own 403.
118
- PLATFORM_HOST_REFUSALS = (400, 404, 421)
119
-
120
-
121
- def guard_verdict(rule: str, remote: bool, status: int, body: bytes) -> Tuple[str, str]:
122
- if status == 403:
123
- return "PASS", "HTTP 403"
124
- disclosed = b"fabric-service/" in (body or b"")
125
- if rule == "network.host-check" and remote and status in PLATFORM_HOST_REFUSALS and not disclosed:
126
- return "PASS", "HTTP %d from the platform router: a foreign Host never reaches the service" % status
127
- return "FAIL", "HTTP %d%s" % (status, ", and the body is the well-known document" if disclosed else "")
60
+ from check_service_rules import PLATFORM_HOST_REFUSALS # noqa: E402,F401 - moved (FAA-65)
61
+ from check_service_rules import plist_problems # noqa: E402,F401 - moved (FAA-65)
62
+ from check_service_rules import marker_problem # noqa: E402,F401 - moved (FAA-65)
63
+ from check_service_rules import priority_problems # noqa: E402,F401 - moved (FAA-65)
64
+ from check_service_rules import guard_verdict # noqa: E402,F401 - moved (FAA-65)
65
+ from check_service_rules import board_responder_verdict # noqa: E402,F401 - moved (FAA-65)
66
+ from check_service_rules import session_lifetime_problem # noqa: E402,F401 - moved (FAA-65)
67
+ from check_service_rules import _semver # noqa: E402,F401 - moved (FAA-65)
68
+ from check_service_rules import usage_problems # noqa: E402,F401 - moved (FAA-65)
69
+ from check_service_rules import same_repository # noqa: E402,F401 - moved (FAA-65)
128
70
 
129
71
 
130
72
  class _PinnedHTTPS(http.client.HTTPSConnection):
@@ -729,7 +671,7 @@ class Probe:
729
671
  marker or "%s: %s=launchd, so a copy that finds the lock held backs off" % (plist_path.name, fs.SUPERVISOR_ENV))
730
672
  slow = priority_problems(plist)
731
673
  self.add("lifecycle.priority", "FAIL" if slow else "PASS",
732
- "; ".join(slow) + " — macOS may starve the service under load and hosts then see an outage; use ProcessType Standard"
674
+ "; ".join(slow) + ". macOS may starve the service under load and hosts then see an outage; use ProcessType Standard"
733
675
  if slow else "%s: scheduled as a standard process" % plist_path.name)
734
676
  if sys.platform != "darwin" or not shutil.which("launchctl"):
735
677
  self.add("lifecycle.one-copy", "NOT_RUN", "launchctl is not available")
@@ -839,146 +781,6 @@ class Probe:
839
781
  return self.results
840
782
 
841
783
 
842
- def board_responder_verdict(wk: Any, kit: Optional[str] = None) -> Tuple[str, str]:
843
- """board.responder: NOT_RUN when the well-known document declares no fabric-project-comms revision; FAIL when it
844
- declares one this kit does not read or the kit's fixture conversation finds a problem; PASS otherwise. `kit` is the
845
- service's own copy (a .py or .mjs path); by default the kit beside this probe."""
846
- protocols = wk.get("protocols") if isinstance(wk, dict) else None
847
- declared = [p for p in protocols if isinstance(p, str) and p.startswith("fabric-project-comms/")] if isinstance(protocols, list) else []
848
- if not declared:
849
- return "NOT_RUN", "the service declares no board participation (no fabric-project-comms revision in protocols)"
850
- accepted = fs.accepted_revisions("fabric-project-comms")
851
- unread = [p for p in declared if "error" in fs.negotiate_revision(p, accepted)]
852
- if unread:
853
- return "FAIL", "declares %s, which this kit does not read (it reads %s)" % (", ".join(unread), ", ".join(accepted))
854
- try:
855
- if kit and kit.endswith(".mjs"):
856
- if not shutil.which("node"):
857
- return "NOT_RUN", "node is not installed to run %s's fixture conversation" % kit
858
- url = Path(kit).resolve().as_uri()
859
- out = subprocess.run(["node", "--input-type=module", "-e",
860
- "import(process.env.FABRIC_BOARD_KIT).then(async (m) => console.log(JSON.stringify(await m.selfCheck())))"],
861
- env=dict(os.environ, FABRIC_BOARD_KIT=url), capture_output=True, text=True, timeout=60)
862
- problems = json.loads(out.stdout.strip().splitlines()[-1]) if out.returncode == 0 and out.stdout.strip() else ["the Node kit did not run: %s" % out.stderr.strip()[:200]]
863
- else:
864
- import importlib.util
865
- path = Path(kit) if kit else Path(__file__).resolve().parent / "fabric_board.py"
866
- spec = importlib.util.spec_from_file_location("fabric_board_under_test", str(path))
867
- module = importlib.util.module_from_spec(spec)
868
- sys.path.insert(0, str(path.resolve().parent))
869
- spec.loader.exec_module(module) # type: ignore[union-attr]
870
- problems = module.self_check()
871
- except Exception as exc: # noqa: BLE001 - a kit that cannot run its conversation fails the rule
872
- return "FAIL", "the kit's fixture conversation did not run: %s" % exc.__class__.__name__
873
- if problems:
874
- return "FAIL", "; ".join(problems)
875
- return "PASS", "declares %s; the kit%s answers the fixture conversation (whole, fenced, no epoch)" % (
876
- ", ".join(declared), " at %s" % kit if kit else " beside this probe")
877
-
878
-
879
- def session_lifetime_problem(set_cookie: str, now: Optional[float] = None) -> Optional[str]:
880
- """DEC-0039: a session cookie set at sign-in lives at most 7 days. Max-Age wins over Expires (RFC 6265
881
- §5.3); a cookie with neither ends with the browser session. None when it is within the bound."""
882
- attrs = {}
883
- for part in set_cookie.split(";")[1:]:
884
- name, _, value = part.strip().partition("=")
885
- attrs[name.strip().lower()] = value.strip()
886
- bound = fs.OPERATOR_SESSION_MAX_SECONDS
887
- if "max-age" in attrs:
888
- if not re.fullmatch(r"-?\d+", attrs["max-age"]):
889
- return "the session cookie's Max-Age %r is not a number" % attrs["max-age"]
890
- if int(attrs["max-age"]) > bound:
891
- return "the session cookie's Max-Age %s outlives 7 days (%d s, DEC-0039)" % (attrs["max-age"], bound)
892
- return None
893
- if "expires" in attrs:
894
- try:
895
- at = email.utils.parsedate_to_datetime(attrs["expires"]).timestamp()
896
- except (TypeError, ValueError, IndexError, OverflowError):
897
- return "the session cookie's Expires %r is not a date" % attrs["expires"]
898
- if at - (time.time() if now is None else now) > bound:
899
- return "the session cookie's Expires %s outlives 7 days (DEC-0039)" % attrs["expires"]
900
- return None
901
-
902
-
903
- def _semver(text: str) -> Tuple[int, int, int]:
904
- m = re.match(r"^(\d+)\.(\d+)\.(\d+)", text or "")
905
- return (int(m.group(1)), int(m.group(2)), int(m.group(3))) if m else (0, 0, 0)
906
-
907
-
908
- def usage_problems(report: Any, service_id: str, instance: str) -> List[str]:
909
- """What makes this not a DEC-0021 usage report of the service: shape, identity and the sums of
910
- FAC-SEM-025. An unknown cost must be null; a day's totals are the sums of its models."""
911
- if not isinstance(report, dict):
912
- return ["not an object"]
913
- out: List[str] = []
914
- if report.get("protocol") != fs.PROTOCOL:
915
- out.append("protocol is %r" % report.get("protocol"))
916
- if report.get("service") != {"id": service_id, "instance": instance}:
917
- out.append("reports for %r, not %s.%s" % (report.get("service"), service_id, instance))
918
- if report.get("currency") != "USD":
919
- out.append("currency is not USD")
920
- days = report.get("days")
921
- if not isinstance(days, list) or len(days) > fs.USAGE_DAYS:
922
- return out + ["days is not a list of at most 31"]
923
- fields = ("calls", "unpricedCalls", "unmeasuredCalls", "inputTokens", "outputTokens", "cacheReadTokens", "cacheWriteTokens")
924
-
925
- def priced(row: Dict[str, Any], at: str) -> None:
926
- calls, unpriced, cost = row.get("calls", 0), row.get("unpricedCalls", 0), row.get("costUsd")
927
- if unpriced > calls:
928
- out.append("%s: more unpriced calls than calls" % at)
929
- if row.get("unmeasuredCalls", 0) > calls:
930
- out.append("%s: more calls with unknown tokens than calls (DEC-0091)" % at)
931
- if calls and unpriced == calls and cost is not None:
932
- out.append("%s: every call is unpriced, so the cost must be null, not %r" % (at, cost))
933
- if unpriced < calls and cost is None:
934
- out.append("%s: priced calls carry a cost" % at)
935
- if cost is not None and (not isinstance(cost, (int, float)) or cost < 0):
936
- out.append("%s: costUsd is not a non-negative number" % at)
937
-
938
- previous = ""
939
- for i, day in enumerate(days):
940
- at = "days[%d]" % i
941
- date = str(day.get("date", "")) if isinstance(day, dict) else ""
942
- if not re.match(r"^\d{4}-\d{2}-\d{2}$", date) or date <= previous:
943
- out.append("%s: dates must run forward" % at)
944
- previous = date
945
- priced(day, at)
946
- models = day.get("byModel") if isinstance(day, dict) else None
947
- if not isinstance(models, list):
948
- out.append("%s: byModel missing" % at)
949
- continue
950
- for j, m in enumerate(models):
951
- priced(m, "%s.byModel[%d]" % (at, j))
952
- for f in fields:
953
- if day.get(f, 0) != sum(m.get(f, 0) for m in models):
954
- out.append("%s: %s is not the sum of its models" % (at, f))
955
- known = sum(m["costUsd"] for m in models if isinstance(m.get("costUsd"), (int, float)))
956
- if isinstance(day.get("costUsd"), (int, float)) and abs(day["costUsd"] - known) > 1e-6:
957
- out.append("%s: costUsd is not the sum of its models' known costs" % at)
958
- for j, m in enumerate(models):
959
- # DEC-0046, DEC-0061: a row's route is a login in its vendor's runner, an issued key, or the platform's
960
- # own metered models (a listing in the cloud).
961
- if "route" in m and m["route"] not in fs.USAGE_ROUTES:
962
- out.append("%s.byModel[%d]: route %r is not subscription, key or platform-metered" % (at, j, m["route"]))
963
- # DEC-0065: the window and the project attribution, as the contract's usageRules reads them (FAC-SEM-025).
964
- for finding in fs.usage_findings(report):
965
- path, message = finding["instancePath"], finding["message"]
966
- if path.startswith(("/byProject", "/generatedAt")) or "generatedAt" in message or "exists in its month" in message:
967
- out.append("%s: %s" % (path or "/", message))
968
- return out
969
-
970
-
971
- def same_repository(a: str, b: str) -> bool:
972
- """git@github.com:o/r.git, https://github.com/o/r and github.com/o/r are one repository."""
973
- def norm(u: str) -> str:
974
- u = u.strip().lower()
975
- u = re.sub(r"^git@([^:]+):", r"\1/", u)
976
- u = re.sub(r"^[a-z+]+://", "", u)
977
- u = re.sub(r"^[^@/]+@", "", u)
978
- return re.sub(r"\.git$", "", u).rstrip("/")
979
- return bool(a and b) and norm(a) == norm(b)
980
-
981
-
982
784
  def locate(target: Optional[str], descriptor: Optional[str], services_dir: Path) -> Path:
983
785
  if descriptor:
984
786
  return Path(descriptor).expanduser()
@@ -0,0 +1,204 @@
1
+ """The probe's rules that read one thing and need no running service (FAA-65): a plist's marker and priority, the
2
+ network guard's verdict, the board responder's fixture conversation, a session cookie's lifetime, a usage report, and
3
+ whether two repository URLs name one repository. ``check_service.py`` runs them against a live service.
4
+ Standard library only, Python 3.9+."""
5
+ from __future__ import annotations
6
+
7
+ import email.utils
8
+ import json
9
+ import os
10
+ import re
11
+ import shutil
12
+ import subprocess
13
+ import sys
14
+ import time
15
+ from pathlib import Path
16
+ from typing import Any, Dict, List, Optional, Tuple
17
+
18
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
19
+ import fabric_service as fs # noqa: E402 - beside this file
20
+
21
+
22
+ def plist_problems(plist: dict, label: object, token: object = None) -> list:
23
+ """What makes a service's launchd job unfit to stay up: identity, restart, secrets."""
24
+ problems = []
25
+ if plist.get("Label") != label:
26
+ problems.append("Label %r" % plist.get("Label"))
27
+ if plist.get("RunAtLoad") is not True:
28
+ problems.append("RunAtLoad is not true")
29
+ if plist.get("KeepAlive") is not True:
30
+ problems.append("KeepAlive is %r, not true" % plist.get("KeepAlive"))
31
+ for key, value in (plist.get("EnvironmentVariables") or {}).items():
32
+ if re.search(r"(TOKEN|SECRET|PASSWORD|KEY)$", key) and not key.endswith("_FILE"):
33
+ problems.append("secret-like variable %s in the plist" % key)
34
+ if token and token in str(value):
35
+ problems.append("the service token itself is in the plist")
36
+ return problems
37
+
38
+
39
+ def marker_problem(plist: dict) -> Optional[str]:
40
+ """What is wrong with the job's supervisor marker (DEC-0057; FAA-05), read the way the copy it starts reads it.
41
+
42
+ Without ``FABRIC_SERVICE_SUPERVISOR=launchd`` (or ``--fabric-supervisor launchd``) a copy that finds the
43
+ lock held exits 75 at once, and KeepAlive starts it again every ThrottleInterval."""
44
+ env = plist.get("EnvironmentVariables")
45
+ env = {str(k): str(v) for k, v in env.items()} if isinstance(env, dict) else {}
46
+ argv = plist.get("ProgramArguments")
47
+ argv = [str(a) for a in argv] if isinstance(argv, list) else []
48
+ marker = fs.supervisor_marker(env, argv)
49
+ if marker["kind"] == "supervised" and marker["manager"] == "launchd":
50
+ return None
51
+ fix = ("a copy that finds the lock held exits 75 at once and KeepAlive respawns it every ThrottleInterval; "
52
+ "regenerate the plist with launchd_plist / launchdPlist and reinstall")
53
+ if marker["kind"] == "conflict":
54
+ return "%s: %s" % (fs.marker_conflict_message(marker), fix)
55
+ if marker["kind"] == "supervised":
56
+ return "the marker names %s, not launchd: %s" % (marker["manager"], fix)
57
+ if marker.get("unreadable") is not None:
58
+ return "the marker %r names no supervisor: %s" % (marker["unreadable"], fix)
59
+ return "no %s=launchd: %s" % (fs.SUPERVISOR_ENV, fix)
60
+
61
+
62
+ def priority_problems(plist: dict) -> list:
63
+ """A service that answers hosts and agents must not be scheduled as background work."""
64
+ out = []
65
+ if plist.get("ProcessType", "Standard") in ("Background", "Adaptive"):
66
+ out.append("ProcessType is %s" % plist.get("ProcessType"))
67
+ if isinstance(plist.get("Nice"), int) and plist["Nice"] > 0:
68
+ out.append("Nice is %d" % plist["Nice"])
69
+ if plist.get("LowPriorityIO") is True or plist.get("LowPriorityBackgroundIO") is True:
70
+ out.append("low-priority I/O")
71
+ return out
72
+
73
+
74
+ # A platform router (Heroku, Fly, Render, a CDN) routes by Host, so a request naming a foreign
75
+ # Host never reaches an online service: the router itself answers, typically 404 or 421. That is
76
+ # still a refusal — the service disclosed nothing — so for a remote placement the host check
77
+ # accepts it, as long as the body is not the well-known document. Every other guard request names
78
+ # the right Host, reaches the service, and must be the service's own 403.
79
+ PLATFORM_HOST_REFUSALS = (400, 404, 421)
80
+
81
+
82
+ def guard_verdict(rule: str, remote: bool, status: int, body: bytes) -> Tuple[str, str]:
83
+ if status == 403:
84
+ return "PASS", "HTTP 403"
85
+ disclosed = b"fabric-service/" in (body or b"")
86
+ if rule == "network.host-check" and remote and status in PLATFORM_HOST_REFUSALS and not disclosed:
87
+ return "PASS", "HTTP %d from the platform router: a foreign Host never reaches the service" % status
88
+ return "FAIL", "HTTP %d%s" % (status, ", and the body is the well-known document" if disclosed else "")
89
+
90
+
91
+ def board_responder_verdict(wk: Any, kit: Optional[str] = None) -> Tuple[str, str]:
92
+ """board.responder: NOT_RUN when the well-known document declares no fabric-project-comms revision; FAIL when it
93
+ declares one this kit does not read or the kit's fixture conversation finds a problem; PASS otherwise. `kit` is the
94
+ service's own copy (a .py or .mjs path); by default the kit beside this probe."""
95
+ protocols = wk.get("protocols") if isinstance(wk, dict) else None
96
+ declared = [p for p in protocols if isinstance(p, str) and p.startswith("fabric-project-comms/")] if isinstance(protocols, list) else []
97
+ if not declared:
98
+ return "NOT_RUN", "the service declares no board participation (no fabric-project-comms revision in protocols)"
99
+ accepted = fs.accepted_revisions("fabric-project-comms")
100
+ unread = [p for p in declared if "error" in fs.negotiate_revision(p, accepted)]
101
+ if unread:
102
+ return "FAIL", "declares %s, which this kit does not read (it reads %s)" % (", ".join(unread), ", ".join(accepted))
103
+ try:
104
+ if kit and kit.endswith(".mjs"):
105
+ if not shutil.which("node"):
106
+ return "NOT_RUN", "node is not installed to run %s's fixture conversation" % kit
107
+ url = Path(kit).resolve().as_uri()
108
+ out = subprocess.run(["node", "--input-type=module", "-e",
109
+ "import(process.env.FABRIC_BOARD_KIT).then(async (m) => console.log(JSON.stringify(await m.selfCheck())))"],
110
+ env=dict(os.environ, FABRIC_BOARD_KIT=url), capture_output=True, text=True, timeout=60)
111
+ problems = json.loads(out.stdout.strip().splitlines()[-1]) if out.returncode == 0 and out.stdout.strip() else ["the Node kit did not run: %s" % out.stderr.strip()[:200]]
112
+ else:
113
+ # A clean interpreter: the kit is several modules (FAA-65), and modules this probe already imported from
114
+ # beside it would stand in for the copy under test.
115
+ path = Path(kit) if kit else Path(__file__).resolve().parent / "fabric_board.py"
116
+ code = ("import json, sys; sys.path.insert(0, sys.argv[1]); import %s as board; "
117
+ "print(json.dumps(board.self_check()))" % path.stem)
118
+ out = subprocess.run([sys.executable, "-E", "-s", "-c", code, str(path.resolve().parent)], capture_output=True,
119
+ text=True, timeout=60, cwd=str(path.resolve().parent))
120
+ problems = json.loads(out.stdout.strip().splitlines()[-1]) if out.returncode == 0 and out.stdout.strip() else ["the kit did not run: %s" % out.stderr.strip()[-200:]]
121
+ except Exception as exc: # noqa: BLE001 - a kit that cannot run its conversation fails the rule
122
+ return "FAIL", "the kit's fixture conversation did not run: %s" % exc.__class__.__name__
123
+ if problems:
124
+ return "FAIL", "; ".join(problems)
125
+ return "PASS", "declares %s; the kit%s answers the fixture conversation (whole, fenced, no epoch)" % (
126
+ ", ".join(declared), " at %s" % kit if kit else " beside this probe")
127
+
128
+
129
+ def session_lifetime_problem(set_cookie: str, now: Optional[float] = None) -> Optional[str]:
130
+ """DEC-0039: a session cookie set at sign-in lives at most 7 days. Max-Age wins over Expires (RFC 6265
131
+ §5.3); a cookie with neither ends with the browser session. None when it is within the bound."""
132
+ attrs = {}
133
+ for part in set_cookie.split(";")[1:]:
134
+ name, _, value = part.strip().partition("=")
135
+ attrs[name.strip().lower()] = value.strip()
136
+ bound = fs.OPERATOR_SESSION_MAX_SECONDS
137
+ if "max-age" in attrs:
138
+ if not re.fullmatch(r"-?\d+", attrs["max-age"]):
139
+ return "the session cookie's Max-Age %r is not a number" % attrs["max-age"]
140
+ if int(attrs["max-age"]) > bound:
141
+ return "the session cookie's Max-Age %s outlives 7 days (%d s, DEC-0039)" % (attrs["max-age"], bound)
142
+ return None
143
+ if "expires" in attrs:
144
+ try:
145
+ at = email.utils.parsedate_to_datetime(attrs["expires"]).timestamp()
146
+ except (TypeError, ValueError, IndexError, OverflowError):
147
+ return "the session cookie's Expires %r is not a date" % attrs["expires"]
148
+ if at - (time.time() if now is None else now) > bound:
149
+ return "the session cookie's Expires %s outlives 7 days (DEC-0039)" % attrs["expires"]
150
+ return None
151
+
152
+
153
+ def _semver(text: str) -> Tuple[int, int, int]:
154
+ m = re.match(r"^(\d+)\.(\d+)\.(\d+)", text or "")
155
+ return (int(m.group(1)), int(m.group(2)), int(m.group(3))) if m else (0, 0, 0)
156
+
157
+
158
+ def usage_problems(report: Any, service_id: str, instance: str) -> List[str]:
159
+ """What makes this not a DEC-0021 usage report of the service: shape, identity and the sums of
160
+ FAC-SEM-025. An unknown cost must be null; a day's totals are the sums of its models."""
161
+ if not isinstance(report, dict):
162
+ return ["not an object"]
163
+ out: List[str] = []
164
+ if report.get("protocol") != fs.PROTOCOL:
165
+ out.append("protocol is %r" % report.get("protocol"))
166
+ if report.get("service") != {"id": service_id, "instance": instance}:
167
+ out.append("reports for %r, not %s.%s" % (report.get("service"), service_id, instance))
168
+ if report.get("currency") != "USD":
169
+ out.append("currency is not USD")
170
+ days = report.get("days")
171
+ if not isinstance(days, list) or len(days) > fs.USAGE_DAYS:
172
+ return out + ["days is not a list of at most 31"]
173
+ # The arithmetic of FAC-SEM-025 is the kit's `usage_findings`, the contract's `usageRules` held to its vectors: one
174
+ # implementation, so the probe never disagrees with the kit and never throws on a count that is not a number.
175
+ for i, day in enumerate(days):
176
+ if not isinstance(day, dict):
177
+ out.append("days[%d]: not an object" % i)
178
+ continue
179
+ if not isinstance(day.get("byModel"), list):
180
+ out.append("days[%d]: byModel missing" % i)
181
+ continue
182
+ for row, at in [(day, "days[%d]" % i)] + [(m, "days[%d].byModel[%d]" % (i, j)) for j, m in enumerate(day["byModel"]) if isinstance(m, dict)]:
183
+ cost = row.get("costUsd")
184
+ if cost is not None and (isinstance(cost, bool) or not isinstance(cost, (int, float)) or cost < 0):
185
+ out.append("%s: costUsd is not a non-negative number" % at)
186
+ for j, m in enumerate(day["byModel"]):
187
+ # DEC-0046, DEC-0061: a row's route is a login in its vendor's runner, an issued key, or the platform's
188
+ # own metered models (a listing in the cloud).
189
+ if isinstance(m, dict) and "route" in m and m["route"] not in fs.USAGE_ROUTES:
190
+ out.append("days[%d].byModel[%d]: route %r is not subscription, key or platform-metered" % (i, j, m["route"]))
191
+ for finding in fs.usage_findings(report):
192
+ out.append("%s: %s" % (finding["instancePath"] or "/", finding["message"]))
193
+ return out
194
+
195
+
196
+ def same_repository(a: str, b: str) -> bool:
197
+ """git@github.com:o/r.git, https://github.com/o/r and github.com/o/r are one repository."""
198
+ def norm(u: str) -> str:
199
+ u = u.strip().lower()
200
+ u = re.sub(r"^git@([^:]+):", r"\1/", u)
201
+ u = re.sub(r"^[a-z+]+://", "", u)
202
+ u = re.sub(r"^[^@/]+@", "", u)
203
+ return re.sub(r"\.git$", "", u).rstrip("/")
204
+ return bool(a and b) and norm(a) == norm(b)
@@ -408,7 +408,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
408
408
  for c in report["copies"]:
409
409
  print(" %-8s %s (%s)" % (c["state"], c["path"], c["version"] or "no version marker"))
410
410
  if not report["copies"]:
411
- print(" no kit copy" + (" — services %s declare a dashboard" % ", ".join(report["services"])
411
+ print(" no kit copy" + (" (services %s declare a dashboard)" % ", ".join(report["services"])
412
412
  if report["dashboard"] and report["services"] else ""))
413
413
  if report["services"]:
414
414
  print(" services from this repository: %s" % ", ".join(report["services"]))