flowharness-portability 0.1.0__tar.gz

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 (42) hide show
  1. flowharness_portability-0.1.0/LICENSE +202 -0
  2. flowharness_portability-0.1.0/PKG-INFO +24 -0
  3. flowharness_portability-0.1.0/README.md +10 -0
  4. flowharness_portability-0.1.0/pyproject.toml +27 -0
  5. flowharness_portability-0.1.0/pyproject.toml.orig +29 -0
  6. flowharness_portability-0.1.0/src/portability/__init__.py +6 -0
  7. flowharness_portability-0.1.0/src/portability/api/__init__.py +0 -0
  8. flowharness_portability-0.1.0/src/portability/application/__init__.py +0 -0
  9. flowharness_portability-0.1.0/src/portability/application/registry.py +71 -0
  10. flowharness_portability-0.1.0/src/portability/domain/__init__.py +37 -0
  11. flowharness_portability-0.1.0/src/portability/domain/agentharnesses/__init__.py +7 -0
  12. flowharness_portability-0.1.0/src/portability/domain/agentharnesses/profile.py +22 -0
  13. flowharness_portability-0.1.0/src/portability/domain/agentharnesses/reader.py +210 -0
  14. flowharness_portability-0.1.0/src/portability/domain/agentharnesses/renderer.py +272 -0
  15. flowharness_portability-0.1.0/src/portability/domain/agents_md/__init__.py +6 -0
  16. flowharness_portability-0.1.0/src/portability/domain/agents_md/profile.py +15 -0
  17. flowharness_portability-0.1.0/src/portability/domain/agents_md/renderer.py +142 -0
  18. flowharness_portability-0.1.0/src/portability/domain/artifact.py +172 -0
  19. flowharness_portability-0.1.0/src/portability/domain/bundle.py +86 -0
  20. flowharness_portability-0.1.0/src/portability/domain/capability.py +49 -0
  21. flowharness_portability-0.1.0/src/portability/domain/claude_code/__init__.py +7 -0
  22. flowharness_portability-0.1.0/src/portability/domain/claude_code/profile.py +28 -0
  23. flowharness_portability-0.1.0/src/portability/domain/claude_code/reader.py +217 -0
  24. flowharness_portability-0.1.0/src/portability/domain/claude_code/renderer.py +277 -0
  25. flowharness_portability-0.1.0/src/portability/domain/continue_/__init__.py +10 -0
  26. flowharness_portability-0.1.0/src/portability/domain/continue_/profile.py +23 -0
  27. flowharness_portability-0.1.0/src/portability/domain/continue_/renderer.py +200 -0
  28. flowharness_portability-0.1.0/src/portability/domain/cursor/__init__.py +6 -0
  29. flowharness_portability-0.1.0/src/portability/domain/cursor/profile.py +16 -0
  30. flowharness_portability-0.1.0/src/portability/domain/cursor/renderer.py +194 -0
  31. flowharness_portability-0.1.0/src/portability/domain/fidelity.py +67 -0
  32. flowharness_portability-0.1.0/src/portability/domain/kinds.py +34 -0
  33. flowharness_portability-0.1.0/src/portability/domain/opencode/__init__.py +6 -0
  34. flowharness_portability-0.1.0/src/portability/domain/opencode/profile.py +24 -0
  35. flowharness_portability-0.1.0/src/portability/domain/opencode/renderer.py +234 -0
  36. flowharness_portability-0.1.0/src/portability/domain/render_result.py +11 -0
  37. flowharness_portability-0.1.0/src/portability/domain/renderer.py +45 -0
  38. flowharness_portability-0.1.0/src/portability/domain/sidecar.py +106 -0
  39. flowharness_portability-0.1.0/src/portability/domain/slug.py +10 -0
  40. flowharness_portability-0.1.0/src/portability/domain/text.py +89 -0
  41. flowharness_portability-0.1.0/src/portability/infrastructure/__init__.py +0 -0
  42. flowharness_portability-0.1.0/src/portability/py.typed +0 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: flowharness-portability
3
+ Version: 0.1.0
4
+ Summary: Portability context (ARTIFACT_PORTABILITY_SPEC §0) — the canonical artifact model + the flowharness/v1 lossless sidecar codec
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Programming Language :: Python :: 3.12
9
+ Classifier: Programming Language :: Python :: 3.13
10
+ Requires-Dist: flowharness-core==0.1.0
11
+ Requires-Python: >=3.12
12
+ Project-URL: Homepage, https://github.com/flowharness-ai
13
+ Description-Content-Type: text/markdown
14
+
15
+ # flowharness-portability
16
+
17
+ Portability context — the canonical artifact model and the `flowharness/v1` lossless sidecar codec. Provides the domain layer for importing and exporting evaluation artifacts across different AI harness systems, with per-harness reader/renderer adapters for the hub-and-spoke architecture.
18
+
19
+ This is an **internal library package** of the FlowHarness toolchain, published to PyPI as a transitive dependency of [`flowharness`](https://github.com/flowharness-ai) (the scan CLI) and [`flowharness-ci-runner`](https://github.com/flowharness-ai). Install those packages instead of depending on `flowharness-portability` directly.
20
+
21
+ > **Note:** this package currently installs a top-level module named `portability`. Prefer `uvx` (isolated environments) over `pip install` into a shared venv until the 0.2 module-namespace rename lands.
22
+
23
+ **License:** Apache-2.0
24
+ **Homepage:** https://github.com/flowharness-ai
@@ -0,0 +1,10 @@
1
+ # flowharness-portability
2
+
3
+ Portability context — the canonical artifact model and the `flowharness/v1` lossless sidecar codec. Provides the domain layer for importing and exporting evaluation artifacts across different AI harness systems, with per-harness reader/renderer adapters for the hub-and-spoke architecture.
4
+
5
+ This is an **internal library package** of the FlowHarness toolchain, published to PyPI as a transitive dependency of [`flowharness`](https://github.com/flowharness-ai) (the scan CLI) and [`flowharness-ci-runner`](https://github.com/flowharness-ai). Install those packages instead of depending on `flowharness-portability` directly.
6
+
7
+ > **Note:** this package currently installs a top-level module named `portability`. Prefer `uvx` (isolated environments) over `pip install` into a shared venv until the 0.2 module-namespace rename lands.
8
+
9
+ **License:** Apache-2.0
10
+ **Homepage:** https://github.com/flowharness-ai
@@ -0,0 +1,27 @@
1
+ [project]
2
+ name = "flowharness-portability"
3
+ version = "0.1.0"
4
+ readme = "README.md"
5
+ description = "Portability context (ARTIFACT_PORTABILITY_SPEC §0) — the canonical artifact model + the flowharness/v1 lossless sidecar codec"
6
+ requires-python = ">=3.12"
7
+ license = "Apache-2.0"
8
+ license-files = ["LICENSE"]
9
+ classifiers = [
10
+ "Development Status :: 3 - Alpha",
11
+ "Programming Language :: Python :: 3.12",
12
+ "Programming Language :: Python :: 3.13",
13
+ ]
14
+ dependencies = ["flowharness-core==0.1.0"]
15
+
16
+ [project.urls]
17
+ Homepage = "https://github.com/flowharness-ai"
18
+
19
+ [build-system]
20
+ requires = ["uv_build>=0.9.0,<0.10.0"]
21
+ build-backend = "uv_build"
22
+
23
+ [tool.uv.build-backend]
24
+ module-name = "portability"
25
+
26
+ [tool.uv.sources.flowharness-core]
27
+ workspace = true
@@ -0,0 +1,29 @@
1
+ [project]
2
+ name = "flowharness-portability"
3
+ version = "0.1.0"
4
+ readme = "README.md"
5
+ description = "Portability context (ARTIFACT_PORTABILITY_SPEC §0) — the canonical artifact model + the flowharness/v1 lossless sidecar codec"
6
+ requires-python = ">=3.12"
7
+ license = "Apache-2.0"
8
+ license-files = ["LICENSE"]
9
+ classifiers = [
10
+ "Development Status :: 3 - Alpha",
11
+ "Programming Language :: Python :: 3.12",
12
+ "Programming Language :: Python :: 3.13",
13
+ ]
14
+ # Internal deps pin ==0.1.0: the six OSS packages version in lockstep (release.yml builds
15
+ # them from one tag), and [tool.uv.sources] workspace=true overrides these locally.
16
+ dependencies = ["flowharness-core==0.1.0"]
17
+
18
+ [project.urls]
19
+ Homepage = "https://github.com/flowharness-ai"
20
+
21
+ [build-system]
22
+ requires = ["uv_build>=0.9.0,<0.10.0"]
23
+ build-backend = "uv_build"
24
+
25
+ [tool.uv.build-backend]
26
+ module-name = "portability"
27
+
28
+ [tool.uv.sources]
29
+ flowharness-core = { workspace = true }
@@ -0,0 +1,6 @@
1
+ """Portability context (ARTIFACT_PORTABILITY_SPEC §0).
2
+
3
+ The canonical artifact model (the hub of the hub-and-spoke) and the ``flowharness/v1``
4
+ lossless sidecar codec. Per-harness reader/renderer adapters live in this context's
5
+ ``domain``/``infrastructure``. Imports stdlib + ``core`` only.
6
+ """
@@ -0,0 +1,71 @@
1
+ """HarnessRendererRegistry — name-keyed registry of the shipped harness renderers (spec §4.4).
2
+
3
+ Mirrors rendering's ``AdapterRegistry`` shape: a name->renderer map plus an ordered list
4
+ (registration order is the presentation order surfaced by ``GET /v1/rendering/harnesses``).
5
+ ``register`` / ``lookup`` / ``names`` + a seed-then-``freeze`` lifecycle. A new harness is
6
+ added by registering its renderer — no central switch. Application layer: only the endpoint
7
+ selects renderers; the portability domain never needs the registry.
8
+
9
+ A post-freeze ``register`` raises ``core.DomainError("harness_registry_frozen")`` (D-3.4): a
10
+ NEW code, portability-local. Rendering's twin raises ``RenderingError`` in ITS context; the
11
+ two contexts keep distinct error conventions rather than share one code.
12
+ """
13
+
14
+ from core import DomainError
15
+ from portability.domain.agentharnesses import AgentHarnessRenderer
16
+ from portability.domain.agents_md import AgentsMdRenderer
17
+ from portability.domain.claude_code import ClaudeCodeRenderer
18
+ from portability.domain.continue_ import ContinueRenderer
19
+ from portability.domain.cursor import CursorRenderer
20
+ from portability.domain.opencode import OpenCodeRenderer
21
+ from portability.domain.renderer import HarnessRenderer
22
+
23
+ __all__ = ["HarnessRendererRegistry", "build_harness_registry"]
24
+
25
+
26
+ class HarnessRendererRegistry:
27
+ """A mutable-at-seed-time, frozen-at-runtime registry of harness renderers, keyed by name."""
28
+
29
+ __slots__ = ("_frozen", "_order", "_renderers")
30
+
31
+ def __init__(self) -> None:
32
+ self._renderers: dict[str, HarnessRenderer] = {}
33
+ self._order: list[str] = []
34
+ self._frozen = False
35
+
36
+ def register(self, renderer: HarnessRenderer) -> None:
37
+ if self._frozen:
38
+ raise DomainError("harness_registry_frozen")
39
+ name = renderer.name()
40
+ if name not in self._renderers:
41
+ self._order.append(name)
42
+ self._renderers[name] = renderer
43
+
44
+ def lookup(self, name: str) -> HarnessRenderer | None:
45
+ return self._renderers.get(name)
46
+
47
+ def names(self) -> tuple[str, ...]:
48
+ return tuple(self._order)
49
+
50
+ def freeze(self) -> None:
51
+ self._frozen = True
52
+
53
+
54
+ def build_harness_registry() -> HarnessRendererRegistry:
55
+ """A fresh registry seeded with the six shipped renderers in fixed presentation order.
56
+
57
+ Left UNFROZEN — the composition root (``wire_portability``, T4) freezes it. Order is
58
+ ``claude_code`` then ``agentharnesses`` then ``agents_md`` then ``cursor`` then ``continue``
59
+ then ``opencode`` (registration order == presentation order); ``agents_md`` is the render-only
60
+ AGENTS.md adapter added by PR-13D, ``cursor`` the render-only ``.cursor/`` adapter added by
61
+ PR-13E, and ``continue``/``opencode`` the render-only ``.continue/``/``.opencode/`` adapters
62
+ added by PR-13F (completing the six-harness set).
63
+ """
64
+ registry = HarnessRendererRegistry()
65
+ registry.register(ClaudeCodeRenderer())
66
+ registry.register(AgentHarnessRenderer())
67
+ registry.register(AgentsMdRenderer())
68
+ registry.register(CursorRenderer())
69
+ registry.register(ContinueRenderer())
70
+ registry.register(OpenCodeRenderer())
71
+ return registry
@@ -0,0 +1,37 @@
1
+ """Portability domain — the canonical artifact model + the flowharness/v1 sidecar codec.
2
+
3
+ Stdlib + ``core`` only (no Pydantic/SQLAlchemy/network/proto). Frozen value objects;
4
+ content-addressed ids via ``core.ContentHashable``; float-free, canonical-JSON-safe.
5
+ """
6
+
7
+ from portability.domain.artifact import (
8
+ CanonicalArtifact,
9
+ Provenance,
10
+ Resource,
11
+ Scope,
12
+ ScopeKind,
13
+ )
14
+ from portability.domain.bundle import ArtifactBundle, Blob, blob_hash
15
+ from portability.domain.capability import Capability, CapabilityProfile
16
+ from portability.domain.kinds import ArtifactKind, Outcome
17
+ from portability.domain.renderer import HarnessRenderer
18
+ from portability.domain.sidecar import SIDECAR_VERSION, decode_bundle, encode_bundle
19
+
20
+ __all__ = [
21
+ "SIDECAR_VERSION",
22
+ "ArtifactBundle",
23
+ "ArtifactKind",
24
+ "Blob",
25
+ "CanonicalArtifact",
26
+ "Capability",
27
+ "CapabilityProfile",
28
+ "HarnessRenderer",
29
+ "Outcome",
30
+ "Provenance",
31
+ "Resource",
32
+ "Scope",
33
+ "ScopeKind",
34
+ "blob_hash",
35
+ "decode_bundle",
36
+ "encode_bundle",
37
+ ]
@@ -0,0 +1,7 @@
1
+ """agentharnesses adapter — the first per-harness reader/renderer over the canonical model."""
2
+
3
+ from portability.domain.agentharnesses.profile import AGENTHARNESSES_PROFILE
4
+ from portability.domain.agentharnesses.reader import AgentHarnessReader
5
+ from portability.domain.agentharnesses.renderer import AgentHarnessRenderer
6
+
7
+ __all__ = ["AGENTHARNESSES_PROFILE", "AgentHarnessReader", "AgentHarnessRenderer"]
@@ -0,0 +1,22 @@
1
+ """The agentharnesses CapabilityProfile (ARTIFACT_PORTABILITY_SPEC §4).
2
+
3
+ agentharnesses natively expresses only skills (+ bundled resources) under a progressive-
4
+ disclosure tree with frontmatter. It has no native tool/mcp/agent/hook/command/permission
5
+ concept — those degrade to a documented stub on the native surface and are preserved
6
+ losslessly in the .flowharness/ sidecar.
7
+ """
8
+
9
+ from portability.domain.capability import Capability, CapabilityProfile
10
+
11
+ AGENTHARNESSES_PROFILE = CapabilityProfile(
12
+ harness="agentharnesses",
13
+ version="agentharnesses/1",
14
+ supported=frozenset(
15
+ {
16
+ Capability.FRONTMATTER,
17
+ Capability.NATIVE_SKILLS,
18
+ Capability.EXECUTABLE_RESOURCES,
19
+ Capability.HIERARCHICAL_MERGE,
20
+ }
21
+ ),
22
+ )
@@ -0,0 +1,210 @@
1
+ """AgentHarnessReader (ARTIFACT_PORTABILITY_SPEC §0.2) — the spoke→hub parse for agentharnesses.
2
+
3
+ Two modes:
4
+ - **sidecar** (lossless): if the always-on ``.flowharness/`` sidecar is present, decode it —
5
+ every artifact kind round-trips byte-for-byte, closing ``parse(render(b)) == b``.
6
+ - **native** (best-effort ingest): a sidecar-less, real-world agentharnesses directory
7
+ (``HARNESS.md`` + ``skills/**/SKILL.md`` + ``references/``) parsed into the skill/rule/
8
+ knowledge slice. Tolerant — never raises on content. Each file is assigned to its nearest
9
+ enclosing skill leaf; markdown ``references/*.md`` become knowledge; routing files and
10
+ non-markdown reference files are NOT ingested (emit the sidecar for full fidelity).
11
+
12
+ A present ``.flowharness/manifest.json`` selects the STRICT sidecar path — a malformed or
13
+ wrong-version sidecar is a hard error, not a silent native fallback. Stdlib + core only.
14
+ """
15
+
16
+ import re
17
+ from collections.abc import Mapping
18
+
19
+ from portability.domain.artifact import (
20
+ CanonicalArtifact,
21
+ Provenance,
22
+ Resource,
23
+ )
24
+ from portability.domain.bundle import ArtifactBundle, Blob, blob_hash
25
+ from portability.domain.kinds import ArtifactKind
26
+ from portability.domain.sidecar import MANIFEST_PATH, decode_bundle
27
+
28
+ _SOURCE = "agentharnesses"
29
+ _HARNESS_FILE = "HARNESS.md"
30
+ _LEAF_DETECTORS = ".leaf-detectors"
31
+ _FRONTMATTER = re.compile(r"^---\s*\n(.*?)\n---\s*\n?(.*)", re.DOTALL)
32
+
33
+
34
+ def _unquote(value: str) -> str:
35
+ if len(value) >= 2 and value[0] == value[-1] and value[0] in "'\"":
36
+ inner = value[1:-1]
37
+ return inner.replace("''", "'") if value[0] == "'" else inner
38
+ return value
39
+
40
+
41
+ def _read_frontmatter(data: bytes) -> tuple[dict[str, str], str]:
42
+ text = data.decode("utf-8", "replace")
43
+ match = _FRONTMATTER.match(text)
44
+ if match is None:
45
+ return {}, text.strip()
46
+ fields: dict[str, str] = {}
47
+ for line in match.group(1).splitlines():
48
+ stripped = line.strip()
49
+ if not stripped or stripped.startswith("#") or ":" not in stripped:
50
+ continue
51
+ key, _, value = stripped.partition(":")
52
+ fields[key.strip()] = _unquote(value.strip())
53
+ return fields, match.group(2).strip()
54
+
55
+
56
+ def _spec(fields: Mapping[str, str]) -> dict[str, object]:
57
+ description = fields.get("description", "")
58
+ return {"description": description} if description else {}
59
+
60
+
61
+ def _media(data: bytes) -> str:
62
+ try:
63
+ data.decode("utf-8")
64
+ except UnicodeDecodeError:
65
+ return "binary"
66
+ return "text"
67
+
68
+
69
+ def _nonblank(value: str | None, fallback: str) -> str:
70
+ # A non-blank display title (CanonicalArtifact rejects a blank title); fall back so the
71
+ # tolerant reader never raises on a missing/whitespace name.
72
+ return value.strip() if value and value.strip() else fallback
73
+
74
+
75
+ def _skill_leaf_names(files: Mapping[str, bytes]) -> frozenset[str]:
76
+ # The filenames that mark a `skill` leaf — declared in .leaf-detectors, not built in
77
+ # (agentharnesses has no built-in leaf types). Default to SKILL.md when unstated.
78
+ raw = files.get(_LEAF_DETECTORS)
79
+ names: set[str] = set()
80
+ if raw is not None:
81
+ for line in raw.decode("utf-8", "replace").splitlines():
82
+ stripped = line.strip()
83
+ if stripped.startswith("#") or "=" not in stripped:
84
+ continue
85
+ leaf_type, _, rel = stripped.partition("=")
86
+ if leaf_type.strip() == "skill" and rel.strip():
87
+ names.add(rel.strip())
88
+ return frozenset(names or {"SKILL.md"})
89
+
90
+
91
+ def _assign_resources(files: Mapping[str, bytes], skill_paths: list[str]) -> dict[str, list[str]]:
92
+ # Assign each non-leaf file to its NEAREST enclosing skill dir, so a parent skill never
93
+ # absorbs a nested child skill's files (and a child's SKILL.md is never a parent resource).
94
+ skill_path_set = set(skill_paths)
95
+ dirs_by_depth = sorted({p.rsplit("/", 1)[0] for p in skill_paths}, key=len, reverse=True)
96
+ out: dict[str, list[str]] = {skill_dir: [] for skill_dir in dirs_by_depth}
97
+ for path in sorted(files):
98
+ if path in skill_path_set:
99
+ continue
100
+ for skill_dir in dirs_by_depth:
101
+ if path.startswith(skill_dir + "/"):
102
+ out[skill_dir].append(path)
103
+ break
104
+ return out
105
+
106
+
107
+ class AgentHarnessReader:
108
+ def name(self) -> str:
109
+ return _SOURCE
110
+
111
+ def parse(self, files: Mapping[str, bytes]) -> ArtifactBundle:
112
+ if MANIFEST_PATH in files:
113
+ return decode_bundle(files) # the always-on lossless sidecar
114
+ return self._parse_native(files)
115
+
116
+ def _parse_native(self, files: Mapping[str, bytes]) -> ArtifactBundle:
117
+ leaf_names = _skill_leaf_names(files)
118
+ skill_paths = sorted(
119
+ path
120
+ for path in files
121
+ if path.startswith("skills/") and path.rsplit("/", 1)[-1] in leaf_names
122
+ )
123
+ resources_by_dir = _assign_resources(files, skill_paths)
124
+ consumed: set[str] = set(skill_paths)
125
+ for paths in resources_by_dir.values():
126
+ consumed.update(paths)
127
+ blobs: dict[str, bytes] = {}
128
+ artifacts: list[CanonicalArtifact] = []
129
+
130
+ artifacts.extend(self._parse_harness(files, consumed))
131
+ for skill_path in skill_paths:
132
+ skill_dir = skill_path.rsplit("/", 1)[0]
133
+ artifacts.append(
134
+ self._parse_skill(skill_path, skill_dir, files, resources_by_dir[skill_dir], blobs)
135
+ )
136
+ artifacts.extend(self._parse_references(files, consumed))
137
+
138
+ blob_objs = tuple(Blob(content_hash=h, data=d) for h, d in sorted(blobs.items()))
139
+ return ArtifactBundle(artifacts=tuple(artifacts), blobs=blob_objs)
140
+
141
+ def _parse_harness(
142
+ self, files: Mapping[str, bytes], consumed: set[str]
143
+ ) -> list[CanonicalArtifact]:
144
+ data = files.get(_HARNESS_FILE)
145
+ if data is None:
146
+ return []
147
+ consumed.add(_HARNESS_FILE)
148
+ fields, body = _read_frontmatter(data)
149
+ return [
150
+ CanonicalArtifact(
151
+ kind=ArtifactKind.RULE,
152
+ title=_nonblank(fields.get("name"), "harness"),
153
+ spec=_spec(fields),
154
+ body=body,
155
+ provenance=Provenance(source_harness=_SOURCE, source_ref=_HARNESS_FILE),
156
+ )
157
+ ]
158
+
159
+ def _parse_skill(
160
+ self,
161
+ skill_path: str,
162
+ skill_dir: str,
163
+ files: Mapping[str, bytes],
164
+ resource_paths: list[str],
165
+ blobs: dict[str, bytes],
166
+ ) -> CanonicalArtifact:
167
+ fields, body = _read_frontmatter(files[skill_path])
168
+ resources: list[Resource] = []
169
+ for path in resource_paths:
170
+ data = files[path]
171
+ content_hash = blob_hash(data)
172
+ blobs[content_hash] = data
173
+ resources.append(
174
+ Resource(
175
+ relpath=path[len(skill_dir) + 1 :],
176
+ content_hash=content_hash,
177
+ media=_media(data),
178
+ )
179
+ )
180
+ name = _nonblank(fields.get("name"), _nonblank(skill_dir.rsplit("/", 1)[-1], "skill"))
181
+ return CanonicalArtifact(
182
+ kind=ArtifactKind.SKILL,
183
+ title=name,
184
+ spec=_spec(fields),
185
+ body=body,
186
+ triggers=(name,),
187
+ resources=tuple(resources),
188
+ provenance=Provenance(source_harness=_SOURCE, source_ref=skill_path),
189
+ )
190
+
191
+ def _parse_references(
192
+ self, files: Mapping[str, bytes], consumed: set[str]
193
+ ) -> list[CanonicalArtifact]:
194
+ out: list[CanonicalArtifact] = []
195
+ for path in sorted(files):
196
+ base = path.rsplit("/", 1)[-1]
197
+ if path in consumed or base.startswith(".") or base == "REFERENCES.md":
198
+ continue
199
+ if path.startswith("references/") and path.endswith(".md"):
200
+ fields, body = _read_frontmatter(files[path])
201
+ out.append(
202
+ CanonicalArtifact(
203
+ kind=ArtifactKind.KNOWLEDGE,
204
+ title=_nonblank(fields.get("title"), _nonblank(base, "reference")),
205
+ spec=_spec(fields),
206
+ body=body,
207
+ provenance=Provenance(source_harness=_SOURCE, source_ref=path),
208
+ )
209
+ )
210
+ return out